{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import *\n",
    "from time import sleep\n",
    "\n",
    "def loadDataSet(fileName):\n",
    "    dataMat = []; labelMat = []\n",
    "    fr = open(fileName)\n",
    "    for line in fr.readlines():\n",
    "        lineArr = line.strip().split('\\t')\n",
    "        dataMat.append([float(lineArr[0]), float(lineArr[1])])\n",
    "        labelMat.append(float(lineArr[2]))\n",
    "    return dataMat,labelMat\n",
    "\n",
    "def selectJrand(i,m):\n",
    "    j=i #we want to select any J not equal to i\n",
    "    while (j==i):\n",
    "        j = int(random.uniform(0,m))\n",
    "    return j\n",
    "\n",
    "def clipAlpha(aj,H,L):\n",
    "    if aj > H: \n",
    "        aj = H\n",
    "    if L > aj:\n",
    "        aj = L\n",
    "    return aj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " 1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0,\n",
       " -1.0]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataArr, labelArr = loadDataSet('testSet.txt')\n",
    "labelArr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def smoSimple(dataMatIn, classLabels, C, toler, maxIter):\n",
    "    dataMatrix = mat(dataMatIn); labelMat = mat(classLabels).transpose()\n",
    "    b = 0; m,n = shape(dataMatrix)\n",
    "    alphas = mat(zeros((m,1)))\n",
    "    iter = 0\n",
    "    while (iter < maxIter):\n",
    "        alphaPairsChanged = 0\n",
    "        for i in range(m):\n",
    "            fXi = float(multiply(alphas,labelMat).T*(dataMatrix*dataMatrix[i,:].T)) + b\n",
    "            Ei = fXi - float(labelMat[i])#if checks if an example violates KKT conditions\n",
    "            if ((labelMat[i]*Ei < -toler) and (alphas[i] < C)) or ((labelMat[i]*Ei > toler) and (alphas[i] > 0)):\n",
    "                j = selectJrand(i,m)\n",
    "                fXj = float(multiply(alphas,labelMat).T*(dataMatrix*dataMatrix[j,:].T)) + b\n",
    "                Ej = fXj - float(labelMat[j])\n",
    "                alphaIold = alphas[i].copy(); alphaJold = alphas[j].copy();\n",
    "                if (labelMat[i] != labelMat[j]):\n",
    "                    L = max(0, alphas[j] - alphas[i])\n",
    "                    H = min(C, C + alphas[j] - alphas[i])\n",
    "                else:\n",
    "                    L = max(0, alphas[j] + alphas[i] - C)\n",
    "                    H = min(C, alphas[j] + alphas[i])\n",
    "                if L==H: print(\"L==H\"); continue\n",
    "                eta = 2.0 * dataMatrix[i,:]*dataMatrix[j,:].T - dataMatrix[i,:]*dataMatrix[i,:].T - dataMatrix[j,:]*dataMatrix[j,:].T\n",
    "                if eta >= 0: print(\"eta>=0\"); continue\n",
    "                alphas[j] -= labelMat[j]*(Ei - Ej)/eta\n",
    "                alphas[j] = clipAlpha(alphas[j],H,L)\n",
    "                if (abs(alphas[j] - alphaJold) < 0.00001): print(\"j not moving enough\"); continue\n",
    "                alphas[i] += labelMat[j]*labelMat[i]*(alphaJold - alphas[j])#update i by the same amount as j\n",
    "                                                                        #the update is in the oppostie direction\n",
    "                b1 = b - Ei- labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[i,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[i,:]*dataMatrix[j,:].T\n",
    "                b2 = b - Ej- labelMat[i]*(alphas[i]-alphaIold)*dataMatrix[i,:]*dataMatrix[j,:].T - labelMat[j]*(alphas[j]-alphaJold)*dataMatrix[j,:]*dataMatrix[j,:].T\n",
    "                if (0 < alphas[i]) and (C > alphas[i]): b = b1\n",
    "                elif (0 < alphas[j]) and (C > alphas[j]): b = b2\n",
    "                else: b = (b1 + b2)/2.0\n",
    "                alphaPairsChanged += 1\n",
    "                print(\"iter: %d i:%d, pairs changed %d\" % (iter,i,alphaPairsChanged))\n",
    "        if (alphaPairsChanged == 0): iter += 1\n",
    "        else: iter = 0\n",
    "        print(\"iteration number: %d\" % iter)\n",
    "    return b,alphas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "L==H\n",
      "L==H\n",
      "iter: 0 i:2, pairs changed 1\n",
      "L==H\n",
      "L==H\n",
      "iter: 0 i:7, pairs changed 2\n",
      "iter: 0 i:8, pairs changed 3\n",
      "iter: 0 i:17, pairs changed 4\n",
      "L==H\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "iter: 0 i:54, pairs changed 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "L==H\n",
      "iteration number: 0\n",
      "L==H\n",
      "iter: 0 i:2, pairs changed 1\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:55, pairs changed 2\n",
      "iter: 0 i:58, pairs changed 3\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "iter: 0 i:70, pairs changed 4\n",
      "iter: 0 i:77, pairs changed 5\n",
      "L==H\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:7, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "iter: 0 i:17, pairs changed 2\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:29, pairs changed 3\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j not moving enough\n",
      "iter: 0 i:54, pairs changed 4\n",
      "iter: 0 i:55, pairs changed 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "iter: 0 i:70, pairs changed 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "L==H\n",
      "iter: 0 i:8, pairs changed 1\n",
      "L==H\n",
      "j not moving enough\n",
      "iter: 0 i:12, pairs changed 2\n",
      "j not moving enough\n",
      "iter: 0 i:23, pairs changed 3\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:31, pairs changed 4\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:54, pairs changed 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:70, pairs changed 6\n",
      "iter: 0 i:76, pairs changed 7\n",
      "L==H\n",
      "iter: 0 i:93, pairs changed 8\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:24, pairs changed 1\n",
      "iter: 0 i:26, pairs changed 2\n",
      "j not moving enough\n",
      "iter: 0 i:29, pairs changed 3\n",
      "iter: 0 i:39, pairs changed 4\n",
      "j not moving enough\n",
      "iter: 0 i:46, pairs changed 5\n",
      "j not moving enough\n",
      "iter: 0 i:54, pairs changed 6\n",
      "iter: 0 i:55, pairs changed 7\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "L==H\n",
      "L==H\n",
      "iter: 0 i:96, pairs changed 8\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "iter: 0 i:0, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:18, pairs changed 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:62, pairs changed 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:70, pairs changed 4\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:20, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "iter: 0 i:55, pairs changed 2\n",
      "iter: 0 i:58, pairs changed 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "L==H\n",
      "iter: 0 i:76, pairs changed 4\n",
      "L==H\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "iter: 0 i:0, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:21, pairs changed 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:29, pairs changed 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:52, pairs changed 4\n",
      "iter: 0 i:54, pairs changed 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:97, pairs changed 6\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "iter: 0 i:5, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:55, pairs changed 2\n",
      "iter: 0 i:62, pairs changed 3\n",
      "j not moving enough\n",
      "iter: 0 i:74, pairs changed 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "L==H\n",
      "L==H\n",
      "L==H\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:12, pairs changed 1\n",
      "L==H\n",
      "j not moving enough\n",
      "iter: 0 i:21, pairs changed 2\n",
      "iter: 0 i:23, pairs changed 3\n",
      "iter: 0 i:24, pairs changed 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:54, pairs changed 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:74, pairs changed 6\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:52, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:69, pairs changed 2\n",
      "iter: 0 i:70, pairs changed 3\n",
      "j not moving enough\n",
      "iter: 0 i:82, pairs changed 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "iter: 0 i:3, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:10, pairs changed 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:29, pairs changed 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:70, pairs changed 4\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "iter: 0 i:8, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "iter: 0 i:17, pairs changed 1\n",
      "iter: 0 i:23, pairs changed 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:30, pairs changed 1\n",
      "iter: 0 i:52, pairs changed 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "iter: 2 i:17, pairs changed 1\n",
      "iter: 2 i:23, pairs changed 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 2 i:55, pairs changed 3\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 0 i:69, pairs changed 1\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 1 i:54, pairs changed 1\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 7 i:29, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 6 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "iter: 3 i:10, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "iter: 4 i:17, pairs changed 1\n",
      "iter: 4 i:29, pairs changed 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "iter: 5 i:54, pairs changed 1\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "j not moving enough\n",
      "iter: 10 i:29, pairs changed 1\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 11\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 12\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 13\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 14\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 15\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 16\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 17\n",
      "j not moving enough\n",
      "iter: 17 i:54, pairs changed 1\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "iter: 5 i:17, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "iter: 5 i:29, pairs changed 1\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 11\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 12\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 13\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 14\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 15\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 16\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 17\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 18\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 19\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 20\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 21\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 22\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 23\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 24\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 25\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 26\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 27\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 28\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 29\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 30\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 31\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 32\n",
      "j not moving enough\n",
      "iter: 32 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 11\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 12\n",
      "j not moving enough\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j not moving enough\n",
      "iteration number: 13\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 14\n",
      "iter: 14 i:17, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "iter: 10 i:54, pairs changed 1\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "iter: 3 i:29, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "iter: 4 i:54, pairs changed 1\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "iter: 10 i:17, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 11\n",
      "iter: 11 i:54, pairs changed 1\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "iter: 3 i:55, pairs changed 1\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "L==H\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "L==H\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iter: 6 i:52, pairs changed 1\n",
      "iteration number: 0\n",
      "iter: 0 i:17, pairs changed 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 11\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 12\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 13\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 14\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 15\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 16\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 17\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 18\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 19\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 20\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 21\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 22\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 23\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 24\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 25\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 26\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 27\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 28\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 29\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 30\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 31\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 32\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 33\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 34\n",
      "iter: 34 i:29, pairs changed 1\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 11\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 12\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 13\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 14\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 15\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 16\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 17\n",
      "j not moving enough\n",
      "j not moving enough\n",
      "iteration number: 18\n",
      "j not moving enough\n",
      "iter: 18 i:52, pairs changed 1\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "iter: 3 i:17, pairs changed 1\n",
      "j not moving enough\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "iter: 7 i:29, pairs changed 1\n",
      "iteration number: 0\n",
      "j not moving enough\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "iteration number: 6\n",
      "j not moving enough\n",
      "iteration number: 7\n",
      "j not moving enough\n",
      "iteration number: 8\n",
      "j not moving enough\n",
      "iteration number: 9\n",
      "j not moving enough\n",
      "iteration number: 10\n",
      "j not moving enough\n",
      "iteration number: 11\n",
      "j not moving enough\n",
      "iteration number: 12\n",
      "j not moving enough\n",
      "iteration number: 13\n",
      "j not moving enough\n",
      "iteration number: 14\n",
      "j not moving enough\n",
      "iteration number: 15\n",
      "j not moving enough\n",
      "iteration number: 16\n",
      "j not moving enough\n",
      "iteration number: 17\n",
      "j not moving enough\n",
      "iteration number: 18\n",
      "j not moving enough\n",
      "iteration number: 19\n",
      "j not moving enough\n",
      "iteration number: 20\n",
      "j not moving enough\n",
      "iteration number: 21\n",
      "j not moving enough\n",
      "iteration number: 22\n",
      "j not moving enough\n",
      "iteration number: 23\n",
      "j not moving enough\n",
      "iteration number: 24\n",
      "j not moving enough\n",
      "iteration number: 25\n",
      "j not moving enough\n",
      "iteration number: 26\n",
      "j not moving enough\n",
      "iteration number: 27\n",
      "j not moving enough\n",
      "iteration number: 28\n",
      "j not moving enough\n",
      "iteration number: 29\n",
      "j not moving enough\n",
      "iteration number: 30\n",
      "j not moving enough\n",
      "iteration number: 31\n",
      "j not moving enough\n",
      "iteration number: 32\n",
      "j not moving enough\n",
      "iteration number: 33\n",
      "j not moving enough\n",
      "iteration number: 34\n",
      "j not moving enough\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration number: 35\n",
      "j not moving enough\n",
      "iteration number: 36\n",
      "j not moving enough\n",
      "iteration number: 37\n",
      "j not moving enough\n",
      "iteration number: 38\n",
      "j not moving enough\n",
      "iteration number: 39\n",
      "j not moving enough\n",
      "iteration number: 40\n"
     ]
    }
   ],
   "source": [
    "b, alphas = smoSimple(dataArr, labelArr, 0.6, 0.001, 40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[-3.83808714]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 0.12748833,  0.24132866,  0.36881699]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alphas[alphas>0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 3)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shape(alphas[alphas>0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4.658191, 3.507396] -1.0\n",
      "[3.457096, -0.082216] -1.0\n",
      "[6.080573, 0.418886] 1.0\n"
     ]
    }
   ],
   "source": [
    "for i in range(100):\n",
    "    if alphas[i]>0.0: print(dataArr[i], labelArr[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''#######********************************\n",
    "Non-Kernel VErsions below\n",
    "'''#######********************************\n",
    "\n",
    "class optStructK:\n",
    "    def __init__(self,dataMatIn, classLabels, C, toler):  # Initialize the structure with the parameters \n",
    "        self.X = dataMatIn\n",
    "        self.labelMat = classLabels\n",
    "        self.C = C\n",
    "        self.tol = toler\n",
    "        self.m = shape(dataMatIn)[0]\n",
    "        self.alphas = mat(zeros((self.m,1)))\n",
    "        self.b = 0\n",
    "        self.eCache = mat(zeros((self.m,2))) #first column is valid flag\n",
    "        \n",
    "def calcEkK(oS, k):\n",
    "    fXk = float(multiply(oS.alphas,oS.labelMat).T*(oS.X*oS.X[k,:].T)) + oS.b\n",
    "    Ek = fXk - float(oS.labelMat[k])\n",
    "    return Ek\n",
    "        \n",
    "def selectJK(i, oS, Ei):         #this is the second choice -heurstic, and calcs Ej\n",
    "    maxK = -1; maxDeltaE = 0; Ej = 0\n",
    "    oS.eCache[i] = [1,Ei]  #set valid #choose the alpha that gives the maximum delta E\n",
    "    validEcacheList = nonzero(oS.eCache[:,0].A)[0]\n",
    "    if (len(validEcacheList)) > 1:\n",
    "        for k in validEcacheList:   #loop through valid Ecache values and find the one that maximizes delta E\n",
    "            if k == i: continue #don't calc for i, waste of time\n",
    "            Ek = calcEkK(oS, k)\n",
    "            deltaE = abs(Ei - Ek)\n",
    "            if (deltaE > maxDeltaE):\n",
    "                maxK = k; maxDeltaE = deltaE; Ej = Ek\n",
    "        return maxK, Ej\n",
    "    else:   #in this case (first time around) we don't have any valid eCache values\n",
    "        j = selectJrand(i, oS.m)\n",
    "        Ej = calcEkK(oS, j)\n",
    "    return j, Ej\n",
    "\n",
    "def updateEkK(oS, k):#after any alpha has changed update the new value in the cache\n",
    "    Ek = calcEkK(oS, k)\n",
    "    oS.eCache[k] = [1,Ek]\n",
    "        \n",
    "def innerLK(i, oS):\n",
    "    Ei = calcEkK(oS, i)\n",
    "    if ((oS.labelMat[i]*Ei < -oS.tol) and (oS.alphas[i] < oS.C)) or ((oS.labelMat[i]*Ei > oS.tol) and (oS.alphas[i] > 0)):\n",
    "        j,Ej = selectJK(i, oS, Ei) #this has been changed from selectJrand\n",
    "        alphaIold = oS.alphas[i].copy(); alphaJold = oS.alphas[j].copy();\n",
    "        if (oS.labelMat[i] != oS.labelMat[j]):\n",
    "            L = max(0, oS.alphas[j] - oS.alphas[i])\n",
    "            H = min(oS.C, oS.C + oS.alphas[j] - oS.alphas[i])\n",
    "        else:\n",
    "            L = max(0, oS.alphas[j] + oS.alphas[i] - oS.C)\n",
    "            H = min(oS.C, oS.alphas[j] + oS.alphas[i])\n",
    "        if L==H: print(\"L==H\"); return 0\n",
    "        eta = 2.0 * oS.X[i,:]*oS.X[j,:].T - oS.X[i,:]*oS.X[i,:].T - oS.X[j,:]*oS.X[j,:].T\n",
    "        if eta >= 0: print(\"eta>=0\"); return 0\n",
    "        oS.alphas[j] -= oS.labelMat[j]*(Ei - Ej)/eta\n",
    "        oS.alphas[j] = clipAlpha(oS.alphas[j],H,L)\n",
    "        updateEkK(oS, j) #added this for the Ecache\n",
    "        if (abs(oS.alphas[j] - alphaJold) < 0.00001): print(\"j not moving enough\"); return 0\n",
    "        oS.alphas[i] += oS.labelMat[j]*oS.labelMat[i]*(alphaJold - oS.alphas[j])#update i by the same amount as j\n",
    "        updateEkK(oS, i) #added this for the Ecache                    #the update is in the oppostie direction\n",
    "        b1 = oS.b - Ei- oS.labelMat[i]*(oS.alphas[i]-alphaIold)*oS.X[i,:]*oS.X[i,:].T - oS.labelMat[j]*(oS.alphas[j]-alphaJold)*oS.X[i,:]*oS.X[j,:].T\n",
    "        b2 = oS.b - Ej- oS.labelMat[i]*(oS.alphas[i]-alphaIold)*oS.X[i,:]*oS.X[j,:].T - oS.labelMat[j]*(oS.alphas[j]-alphaJold)*oS.X[j,:]*oS.X[j,:].T\n",
    "        if (0 < oS.alphas[i]) and (oS.C > oS.alphas[i]): oS.b = b1\n",
    "        elif (0 < oS.alphas[j]) and (oS.C > oS.alphas[j]): oS.b = b2\n",
    "        else: oS.b = (b1 + b2)/2.0\n",
    "        return 1\n",
    "    else: return 0\n",
    "\n",
    "def smoPK(dataMatIn, classLabels, C, toler, maxIter):    #full Platt SMO\n",
    "    oS = optStructK(mat(dataMatIn),mat(classLabels).transpose(),C,toler)\n",
    "    iter = 0\n",
    "    entireSet = True; alphaPairsChanged = 0\n",
    "    while (iter < maxIter) and ((alphaPairsChanged > 0) or (entireSet)):\n",
    "        alphaPairsChanged = 0\n",
    "        if entireSet:   #go over all\n",
    "            for i in range(oS.m):        \n",
    "                alphaPairsChanged += innerLK(i,oS)\n",
    "                print(\"fullSet, iter: %d i:%d, pairs changed %d\" % (iter,i,alphaPairsChanged))\n",
    "            iter += 1\n",
    "        else:#go over non-bound (railed) alphas\n",
    "            nonBoundIs = nonzero((oS.alphas.A > 0) * (oS.alphas.A < C))[0]\n",
    "            for i in nonBoundIs:\n",
    "                alphaPairsChanged += innerLK(i,oS)\n",
    "                print(\"non-bound, iter: %d i:%d, pairs changed %d\" % (iter,i,alphaPairsChanged))\n",
    "            iter += 1\n",
    "        if entireSet: entireSet = False #toggle entire set loop\n",
    "        elif (alphaPairsChanged == 0): entireSet = True  \n",
    "        print(\"iteration number: %d\" % iter)\n",
    "    return oS.b,oS.alphas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fullSet, iter: 0 i:0, pairs changed 1\n",
      "fullSet, iter: 0 i:1, pairs changed 1\n",
      "fullSet, iter: 0 i:2, pairs changed 2\n",
      "fullSet, iter: 0 i:3, pairs changed 3\n",
      "fullSet, iter: 0 i:4, pairs changed 4\n",
      "fullSet, iter: 0 i:5, pairs changed 5\n",
      "fullSet, iter: 0 i:6, pairs changed 6\n",
      "fullSet, iter: 0 i:7, pairs changed 6\n",
      "fullSet, iter: 0 i:8, pairs changed 7\n",
      "fullSet, iter: 0 i:9, pairs changed 7\n",
      "fullSet, iter: 0 i:10, pairs changed 7\n",
      "fullSet, iter: 0 i:11, pairs changed 7\n",
      "fullSet, iter: 0 i:12, pairs changed 7\n",
      "L==H\n",
      "fullSet, iter: 0 i:13, pairs changed 7\n",
      "fullSet, iter: 0 i:14, pairs changed 7\n",
      "L==H\n",
      "fullSet, iter: 0 i:15, pairs changed 7\n",
      "fullSet, iter: 0 i:16, pairs changed 7\n",
      "L==H\n",
      "fullSet, iter: 0 i:17, pairs changed 7\n",
      "fullSet, iter: 0 i:18, pairs changed 8\n",
      "fullSet, iter: 0 i:19, pairs changed 8\n",
      "fullSet, iter: 0 i:20, pairs changed 8\n",
      "fullSet, iter: 0 i:21, pairs changed 8\n",
      "fullSet, iter: 0 i:22, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:23, pairs changed 8\n",
      "fullSet, iter: 0 i:24, pairs changed 8\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:25, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:26, pairs changed 8\n",
      "fullSet, iter: 0 i:27, pairs changed 8\n",
      "fullSet, iter: 0 i:28, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:29, pairs changed 8\n",
      "fullSet, iter: 0 i:30, pairs changed 8\n",
      "fullSet, iter: 0 i:31, pairs changed 8\n",
      "fullSet, iter: 0 i:32, pairs changed 8\n",
      "fullSet, iter: 0 i:33, pairs changed 8\n",
      "fullSet, iter: 0 i:34, pairs changed 8\n",
      "fullSet, iter: 0 i:35, pairs changed 8\n",
      "fullSet, iter: 0 i:36, pairs changed 8\n",
      "fullSet, iter: 0 i:37, pairs changed 8\n",
      "fullSet, iter: 0 i:38, pairs changed 8\n",
      "fullSet, iter: 0 i:39, pairs changed 8\n",
      "fullSet, iter: 0 i:40, pairs changed 8\n",
      "fullSet, iter: 0 i:41, pairs changed 8\n",
      "fullSet, iter: 0 i:42, pairs changed 8\n",
      "fullSet, iter: 0 i:43, pairs changed 8\n",
      "fullSet, iter: 0 i:44, pairs changed 8\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:45, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:46, pairs changed 8\n",
      "fullSet, iter: 0 i:47, pairs changed 8\n",
      "fullSet, iter: 0 i:48, pairs changed 8\n",
      "fullSet, iter: 0 i:49, pairs changed 8\n",
      "fullSet, iter: 0 i:50, pairs changed 8\n",
      "fullSet, iter: 0 i:51, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:52, pairs changed 8\n",
      "fullSet, iter: 0 i:53, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:54, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:55, pairs changed 8\n",
      "fullSet, iter: 0 i:56, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:57, pairs changed 8\n",
      "fullSet, iter: 0 i:58, pairs changed 8\n",
      "fullSet, iter: 0 i:59, pairs changed 8\n",
      "fullSet, iter: 0 i:60, pairs changed 8\n",
      "fullSet, iter: 0 i:61, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:62, pairs changed 8\n",
      "fullSet, iter: 0 i:63, pairs changed 8\n",
      "fullSet, iter: 0 i:64, pairs changed 8\n",
      "fullSet, iter: 0 i:65, pairs changed 8\n",
      "fullSet, iter: 0 i:66, pairs changed 8\n",
      "fullSet, iter: 0 i:67, pairs changed 8\n",
      "fullSet, iter: 0 i:68, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:69, pairs changed 8\n",
      "fullSet, iter: 0 i:70, pairs changed 8\n",
      "fullSet, iter: 0 i:71, pairs changed 8\n",
      "fullSet, iter: 0 i:72, pairs changed 8\n",
      "fullSet, iter: 0 i:73, pairs changed 8\n",
      "fullSet, iter: 0 i:74, pairs changed 8\n",
      "fullSet, iter: 0 i:75, pairs changed 8\n",
      "fullSet, iter: 0 i:76, pairs changed 8\n",
      "fullSet, iter: 0 i:77, pairs changed 8\n",
      "fullSet, iter: 0 i:78, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:79, pairs changed 8\n",
      "fullSet, iter: 0 i:80, pairs changed 8\n",
      "fullSet, iter: 0 i:81, pairs changed 8\n",
      "L==H\n",
      "fullSet, iter: 0 i:82, pairs changed 8\n",
      "fullSet, iter: 0 i:83, pairs changed 8\n",
      "fullSet, iter: 0 i:84, pairs changed 8\n",
      "fullSet, iter: 0 i:85, pairs changed 8\n",
      "fullSet, iter: 0 i:86, pairs changed 8\n",
      "fullSet, iter: 0 i:87, pairs changed 8\n",
      "fullSet, iter: 0 i:88, pairs changed 8\n",
      "fullSet, iter: 0 i:89, pairs changed 8\n",
      "fullSet, iter: 0 i:90, pairs changed 8\n",
      "fullSet, iter: 0 i:91, pairs changed 8\n",
      "fullSet, iter: 0 i:92, pairs changed 8\n",
      "fullSet, iter: 0 i:93, pairs changed 8\n",
      "fullSet, iter: 0 i:94, pairs changed 8\n",
      "fullSet, iter: 0 i:95, pairs changed 8\n",
      "fullSet, iter: 0 i:96, pairs changed 8\n",
      "fullSet, iter: 0 i:97, pairs changed 8\n",
      "fullSet, iter: 0 i:98, pairs changed 8\n",
      "fullSet, iter: 0 i:99, pairs changed 8\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:0, pairs changed 0\n",
      "non-bound, iter: 1 i:2, pairs changed 1\n",
      "non-bound, iter: 1 i:4, pairs changed 2\n",
      "non-bound, iter: 1 i:5, pairs changed 3\n",
      "non-bound, iter: 1 i:6, pairs changed 4\n",
      "non-bound, iter: 1 i:8, pairs changed 5\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:17, pairs changed 5\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:18, pairs changed 5\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:0, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:6, pairs changed 0\n",
      "non-bound, iter: 2 i:8, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:17, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:18, pairs changed 0\n",
      "non-bound, iter: 2 i:55, pairs changed 0\n",
      "iteration number: 3\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:0, pairs changed 0\n",
      "fullSet, iter: 3 i:1, pairs changed 0\n",
      "fullSet, iter: 3 i:2, pairs changed 0\n",
      "fullSet, iter: 3 i:3, pairs changed 0\n",
      "fullSet, iter: 3 i:4, pairs changed 0\n",
      "fullSet, iter: 3 i:5, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:6, pairs changed 0\n",
      "fullSet, iter: 3 i:7, pairs changed 0\n",
      "fullSet, iter: 3 i:8, pairs changed 0\n",
      "fullSet, iter: 3 i:9, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:10, pairs changed 0\n",
      "fullSet, iter: 3 i:11, pairs changed 0\n",
      "fullSet, iter: 3 i:12, pairs changed 0\n",
      "fullSet, iter: 3 i:13, pairs changed 0\n",
      "fullSet, iter: 3 i:14, pairs changed 0\n",
      "fullSet, iter: 3 i:15, pairs changed 0\n",
      "fullSet, iter: 3 i:16, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:17, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:18, pairs changed 0\n",
      "fullSet, iter: 3 i:19, pairs changed 0\n",
      "fullSet, iter: 3 i:20, pairs changed 0\n",
      "fullSet, iter: 3 i:21, pairs changed 0\n",
      "fullSet, iter: 3 i:22, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:23, pairs changed 0\n",
      "fullSet, iter: 3 i:24, pairs changed 0\n",
      "fullSet, iter: 3 i:25, pairs changed 0\n",
      "fullSet, iter: 3 i:26, pairs changed 0\n",
      "fullSet, iter: 3 i:27, pairs changed 0\n",
      "fullSet, iter: 3 i:28, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:29, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:30, pairs changed 0\n",
      "fullSet, iter: 3 i:31, pairs changed 0\n",
      "fullSet, iter: 3 i:32, pairs changed 0\n",
      "fullSet, iter: 3 i:33, pairs changed 0\n",
      "fullSet, iter: 3 i:34, pairs changed 0\n",
      "fullSet, iter: 3 i:35, pairs changed 0\n",
      "fullSet, iter: 3 i:36, pairs changed 0\n",
      "fullSet, iter: 3 i:37, pairs changed 0\n",
      "fullSet, iter: 3 i:38, pairs changed 0\n",
      "fullSet, iter: 3 i:39, pairs changed 0\n",
      "fullSet, iter: 3 i:40, pairs changed 0\n",
      "fullSet, iter: 3 i:41, pairs changed 0\n",
      "fullSet, iter: 3 i:42, pairs changed 0\n",
      "fullSet, iter: 3 i:43, pairs changed 0\n",
      "fullSet, iter: 3 i:44, pairs changed 0\n",
      "fullSet, iter: 3 i:45, pairs changed 0\n",
      "fullSet, iter: 3 i:46, pairs changed 0\n",
      "fullSet, iter: 3 i:47, pairs changed 0\n",
      "fullSet, iter: 3 i:48, pairs changed 0\n",
      "fullSet, iter: 3 i:49, pairs changed 0\n",
      "fullSet, iter: 3 i:50, pairs changed 0\n",
      "fullSet, iter: 3 i:51, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:52, pairs changed 0\n",
      "fullSet, iter: 3 i:53, pairs changed 0\n",
      "fullSet, iter: 3 i:54, pairs changed 0\n",
      "fullSet, iter: 3 i:55, pairs changed 0\n",
      "fullSet, iter: 3 i:56, pairs changed 0\n",
      "fullSet, iter: 3 i:57, pairs changed 0\n",
      "fullSet, iter: 3 i:58, pairs changed 0\n",
      "fullSet, iter: 3 i:59, pairs changed 0\n",
      "fullSet, iter: 3 i:60, pairs changed 0\n",
      "fullSet, iter: 3 i:61, pairs changed 0\n",
      "fullSet, iter: 3 i:62, pairs changed 0\n",
      "fullSet, iter: 3 i:63, pairs changed 0\n",
      "fullSet, iter: 3 i:64, pairs changed 0\n",
      "fullSet, iter: 3 i:65, pairs changed 0\n",
      "fullSet, iter: 3 i:66, pairs changed 0\n",
      "fullSet, iter: 3 i:67, pairs changed 0\n",
      "fullSet, iter: 3 i:68, pairs changed 0\n",
      "fullSet, iter: 3 i:69, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:70, pairs changed 0\n",
      "fullSet, iter: 3 i:71, pairs changed 0\n",
      "fullSet, iter: 3 i:72, pairs changed 0\n",
      "fullSet, iter: 3 i:73, pairs changed 0\n",
      "fullSet, iter: 3 i:74, pairs changed 0\n",
      "fullSet, iter: 3 i:75, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:76, pairs changed 0\n",
      "fullSet, iter: 3 i:77, pairs changed 0\n",
      "fullSet, iter: 3 i:78, pairs changed 0\n",
      "fullSet, iter: 3 i:79, pairs changed 0\n",
      "fullSet, iter: 3 i:80, pairs changed 0\n",
      "fullSet, iter: 3 i:81, pairs changed 0\n",
      "fullSet, iter: 3 i:82, pairs changed 0\n",
      "fullSet, iter: 3 i:83, pairs changed 0\n",
      "fullSet, iter: 3 i:84, pairs changed 0\n",
      "fullSet, iter: 3 i:85, pairs changed 0\n",
      "fullSet, iter: 3 i:86, pairs changed 0\n",
      "fullSet, iter: 3 i:87, pairs changed 0\n",
      "fullSet, iter: 3 i:88, pairs changed 0\n",
      "fullSet, iter: 3 i:89, pairs changed 0\n",
      "fullSet, iter: 3 i:90, pairs changed 0\n",
      "fullSet, iter: 3 i:91, pairs changed 0\n",
      "fullSet, iter: 3 i:92, pairs changed 0\n",
      "fullSet, iter: 3 i:93, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:94, pairs changed 0\n",
      "fullSet, iter: 3 i:95, pairs changed 0\n",
      "fullSet, iter: 3 i:96, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:97, pairs changed 0\n",
      "fullSet, iter: 3 i:98, pairs changed 0\n",
      "fullSet, iter: 3 i:99, pairs changed 0\n",
      "iteration number: 4\n"
     ]
    }
   ],
   "source": [
    "dataArr, labelArr = loadDataSet('testSet.txt')\n",
    "b, alphas = smoPK(dataArr, labelArr, 0.6, 0.001, 40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "def kernelTrans(X, A, kTup): #calc the kernel or transform data to a higher dimensional space\n",
    "    m,n = shape(X)\n",
    "    K = mat(zeros((m,1)))\n",
    "    if kTup[0]=='lin': K = X * A.T   #linear kernel\n",
    "    elif kTup[0]=='rbf':\n",
    "        for j in range(m):\n",
    "            deltaRow = X[j,:] - A\n",
    "            K[j] = deltaRow*deltaRow.T\n",
    "        K = exp(K/(-1*kTup[1]**2)) #divide in NumPy is element-wise not matrix like Matlab\n",
    "    else: raise NameError('Houston We Have a Problem -- \\\n",
    "    That Kernel is not recognized')\n",
    "    return K\n",
    "\n",
    "class optStruct:\n",
    "    def __init__(self,dataMatIn, classLabels, C, toler, kTup):  # Initialize the structure with the parameters \n",
    "        self.X = dataMatIn\n",
    "        self.labelMat = classLabels\n",
    "        self.C = C\n",
    "        self.tol = toler\n",
    "        self.m = shape(dataMatIn)[0]\n",
    "        self.alphas = mat(zeros((self.m,1)))\n",
    "        self.b = 0\n",
    "        self.eCache = mat(zeros((self.m,2))) #first column is valid flag\n",
    "        self.K = mat(zeros((self.m,self.m)))\n",
    "        for i in range(self.m):\n",
    "            self.K[:,i] = kernelTrans(self.X, self.X[i,:], kTup)\n",
    "        \n",
    "def calcEk(oS, k):\n",
    "    fXk = float(multiply(oS.alphas,oS.labelMat).T*oS.K[:,k] + oS.b)\n",
    "    Ek = fXk - float(oS.labelMat[k])\n",
    "    return Ek\n",
    "        \n",
    "def selectJ(i, oS, Ei):         #this is the second choice -heurstic, and calcs Ej\n",
    "    maxK = -1; maxDeltaE = 0; Ej = 0\n",
    "    oS.eCache[i] = [1,Ei]  #set valid #choose the alpha that gives the maximum delta E\n",
    "    validEcacheList = nonzero(oS.eCache[:,0].A)[0]\n",
    "    if (len(validEcacheList)) > 1:\n",
    "        for k in validEcacheList:   #loop through valid Ecache values and find the one that maximizes delta E\n",
    "            if k == i: continue #don't calc for i, waste of time\n",
    "            Ek = calcEk(oS, k)\n",
    "            deltaE = abs(Ei - Ek)\n",
    "            if (deltaE > maxDeltaE):\n",
    "                maxK = k; maxDeltaE = deltaE; Ej = Ek\n",
    "        return maxK, Ej\n",
    "    else:   #in this case (first time around) we don't have any valid eCache values\n",
    "        j = selectJrand(i, oS.m)\n",
    "        Ej = calcEk(oS, j)\n",
    "    return j, Ej\n",
    "\n",
    "def updateEk(oS, k):#after any alpha has changed update the new value in the cache\n",
    "    Ek = calcEk(oS, k)\n",
    "    oS.eCache[k] = [1,Ek]\n",
    "        \n",
    "def innerL(i, oS):\n",
    "    Ei = calcEk(oS, i)\n",
    "    if ((oS.labelMat[i]*Ei < -oS.tol) and (oS.alphas[i] < oS.C)) or ((oS.labelMat[i]*Ei > oS.tol) and (oS.alphas[i] > 0)):\n",
    "        j,Ej = selectJ(i, oS, Ei) #this has been changed from selectJrand\n",
    "        alphaIold = oS.alphas[i].copy(); alphaJold = oS.alphas[j].copy();\n",
    "        if (oS.labelMat[i] != oS.labelMat[j]):\n",
    "            L = max(0, oS.alphas[j] - oS.alphas[i])\n",
    "            H = min(oS.C, oS.C + oS.alphas[j] - oS.alphas[i])\n",
    "        else:\n",
    "            L = max(0, oS.alphas[j] + oS.alphas[i] - oS.C)\n",
    "            H = min(oS.C, oS.alphas[j] + oS.alphas[i])\n",
    "        if L==H: print(\"L==H\"); return 0\n",
    "        eta = 2.0 * oS.K[i,j] - oS.K[i,i] - oS.K[j,j] #changed for kernel\n",
    "        if eta >= 0: print(\"eta>=0\"); return 0\n",
    "        oS.alphas[j] -= oS.labelMat[j]*(Ei - Ej)/eta\n",
    "        oS.alphas[j] = clipAlpha(oS.alphas[j],H,L)\n",
    "        updateEk(oS, j) #added this for the Ecache\n",
    "        if (abs(oS.alphas[j] - alphaJold) < 0.00001): print(\"j not moving enough\"); return 0\n",
    "        oS.alphas[i] += oS.labelMat[j]*oS.labelMat[i]*(alphaJold - oS.alphas[j])#update i by the same amount as j\n",
    "        updateEk(oS, i) #added this for the Ecache                    #the update is in the oppostie direction\n",
    "        b1 = oS.b - Ei- oS.labelMat[i]*(oS.alphas[i]-alphaIold)*oS.K[i,i] - oS.labelMat[j]*(oS.alphas[j]-alphaJold)*oS.K[i,j]\n",
    "        b2 = oS.b - Ej- oS.labelMat[i]*(oS.alphas[i]-alphaIold)*oS.K[i,j]- oS.labelMat[j]*(oS.alphas[j]-alphaJold)*oS.K[j,j]\n",
    "        if (0 < oS.alphas[i]) and (oS.C > oS.alphas[i]): oS.b = b1\n",
    "        elif (0 < oS.alphas[j]) and (oS.C > oS.alphas[j]): oS.b = b2\n",
    "        else: oS.b = (b1 + b2)/2.0\n",
    "        return 1\n",
    "    else: return 0\n",
    "\n",
    "def smoP(dataMatIn, classLabels, C, toler, maxIter,kTup=('lin', 0)):    #full Platt SMO\n",
    "    oS = optStruct(mat(dataMatIn),mat(classLabels).transpose(),C,toler, kTup)\n",
    "    iter = 0\n",
    "    entireSet = True; alphaPairsChanged = 0\n",
    "    while (iter < maxIter) and ((alphaPairsChanged > 0) or (entireSet)):\n",
    "        alphaPairsChanged = 0\n",
    "        if entireSet:   #go over all\n",
    "            for i in range(oS.m):        \n",
    "                alphaPairsChanged += innerL(i,oS)\n",
    "                print(\"fullSet, iter: %d i:%d, pairs changed %d\" % (iter,i,alphaPairsChanged))\n",
    "            iter += 1\n",
    "        else:#go over non-bound (railed) alphas\n",
    "            nonBoundIs = nonzero((oS.alphas.A > 0) * (oS.alphas.A < C))[0]\n",
    "            for i in nonBoundIs:\n",
    "                alphaPairsChanged += innerL(i,oS)\n",
    "                print(\"non-bound, iter: %d i:%d, pairs changed %d\" % (iter,i,alphaPairsChanged))\n",
    "            iter += 1\n",
    "        if entireSet: entireSet = False #toggle entire set loop\n",
    "        elif (alphaPairsChanged == 0): entireSet = True  \n",
    "        print(\"iteration number: %d\" % iter)\n",
    "    return oS.b,oS.alphas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "L==H\n",
      "fullSet, iter: 0 i:0, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 0 i:1, pairs changed 0\n",
      "fullSet, iter: 0 i:2, pairs changed 1\n",
      "L==H\n",
      "fullSet, iter: 0 i:3, pairs changed 1\n",
      "fullSet, iter: 0 i:4, pairs changed 2\n",
      "fullSet, iter: 0 i:5, pairs changed 2\n",
      "fullSet, iter: 0 i:6, pairs changed 2\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:7, pairs changed 2\n",
      "L==H\n",
      "fullSet, iter: 0 i:8, pairs changed 2\n",
      "fullSet, iter: 0 i:9, pairs changed 2\n",
      "L==H\n",
      "fullSet, iter: 0 i:10, pairs changed 2\n",
      "L==H\n",
      "fullSet, iter: 0 i:11, pairs changed 2\n",
      "L==H\n",
      "fullSet, iter: 0 i:12, pairs changed 2\n",
      "fullSet, iter: 0 i:13, pairs changed 2\n",
      "L==H\n",
      "fullSet, iter: 0 i:14, pairs changed 2\n",
      "fullSet, iter: 0 i:15, pairs changed 2\n",
      "fullSet, iter: 0 i:16, pairs changed 2\n",
      "L==H\n",
      "fullSet, iter: 0 i:17, pairs changed 2\n",
      "fullSet, iter: 0 i:18, pairs changed 3\n",
      "fullSet, iter: 0 i:19, pairs changed 3\n",
      "fullSet, iter: 0 i:20, pairs changed 3\n",
      "fullSet, iter: 0 i:21, pairs changed 3\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:22, pairs changed 3\n",
      "L==H\n",
      "fullSet, iter: 0 i:23, pairs changed 3\n",
      "L==H\n",
      "fullSet, iter: 0 i:24, pairs changed 3\n",
      "fullSet, iter: 0 i:25, pairs changed 4\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:26, pairs changed 4\n",
      "fullSet, iter: 0 i:27, pairs changed 4\n",
      "fullSet, iter: 0 i:28, pairs changed 4\n",
      "L==H\n",
      "fullSet, iter: 0 i:29, pairs changed 4\n",
      "fullSet, iter: 0 i:30, pairs changed 4\n",
      "fullSet, iter: 0 i:31, pairs changed 4\n",
      "fullSet, iter: 0 i:32, pairs changed 4\n",
      "fullSet, iter: 0 i:33, pairs changed 4\n",
      "fullSet, iter: 0 i:34, pairs changed 4\n",
      "fullSet, iter: 0 i:35, pairs changed 4\n",
      "fullSet, iter: 0 i:36, pairs changed 4\n",
      "fullSet, iter: 0 i:37, pairs changed 4\n",
      "fullSet, iter: 0 i:38, pairs changed 4\n",
      "fullSet, iter: 0 i:39, pairs changed 4\n",
      "fullSet, iter: 0 i:40, pairs changed 4\n",
      "fullSet, iter: 0 i:41, pairs changed 4\n",
      "fullSet, iter: 0 i:42, pairs changed 4\n",
      "fullSet, iter: 0 i:43, pairs changed 4\n",
      "fullSet, iter: 0 i:44, pairs changed 4\n",
      "fullSet, iter: 0 i:45, pairs changed 4\n",
      "fullSet, iter: 0 i:46, pairs changed 5\n",
      "fullSet, iter: 0 i:47, pairs changed 5\n",
      "fullSet, iter: 0 i:48, pairs changed 5\n",
      "fullSet, iter: 0 i:49, pairs changed 5\n",
      "fullSet, iter: 0 i:50, pairs changed 5\n",
      "fullSet, iter: 0 i:51, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:52, pairs changed 5\n",
      "fullSet, iter: 0 i:53, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:54, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:55, pairs changed 5\n",
      "fullSet, iter: 0 i:56, pairs changed 5\n",
      "fullSet, iter: 0 i:57, pairs changed 5\n",
      "fullSet, iter: 0 i:58, pairs changed 5\n",
      "fullSet, iter: 0 i:59, pairs changed 5\n",
      "fullSet, iter: 0 i:60, pairs changed 5\n",
      "fullSet, iter: 0 i:61, pairs changed 5\n",
      "fullSet, iter: 0 i:62, pairs changed 5\n",
      "fullSet, iter: 0 i:63, pairs changed 5\n",
      "fullSet, iter: 0 i:64, pairs changed 5\n",
      "fullSet, iter: 0 i:65, pairs changed 5\n",
      "fullSet, iter: 0 i:66, pairs changed 5\n",
      "fullSet, iter: 0 i:67, pairs changed 5\n",
      "fullSet, iter: 0 i:68, pairs changed 5\n",
      "L==H\n",
      "fullSet, iter: 0 i:69, pairs changed 5\n",
      "fullSet, iter: 0 i:70, pairs changed 5\n",
      "fullSet, iter: 0 i:71, pairs changed 5\n",
      "fullSet, iter: 0 i:72, pairs changed 5\n",
      "fullSet, iter: 0 i:73, pairs changed 5\n",
      "fullSet, iter: 0 i:74, pairs changed 5\n",
      "fullSet, iter: 0 i:75, pairs changed 5\n",
      "fullSet, iter: 0 i:76, pairs changed 5\n",
      "fullSet, iter: 0 i:77, pairs changed 5\n",
      "fullSet, iter: 0 i:78, pairs changed 5\n",
      "fullSet, iter: 0 i:79, pairs changed 5\n",
      "fullSet, iter: 0 i:80, pairs changed 5\n",
      "fullSet, iter: 0 i:81, pairs changed 5\n",
      "fullSet, iter: 0 i:82, pairs changed 5\n",
      "fullSet, iter: 0 i:83, pairs changed 5\n",
      "fullSet, iter: 0 i:84, pairs changed 5\n",
      "fullSet, iter: 0 i:85, pairs changed 5\n",
      "fullSet, iter: 0 i:86, pairs changed 5\n",
      "fullSet, iter: 0 i:87, pairs changed 5\n",
      "fullSet, iter: 0 i:88, pairs changed 5\n",
      "fullSet, iter: 0 i:89, pairs changed 5\n",
      "fullSet, iter: 0 i:90, pairs changed 5\n",
      "fullSet, iter: 0 i:91, pairs changed 5\n",
      "fullSet, iter: 0 i:92, pairs changed 5\n",
      "fullSet, iter: 0 i:93, pairs changed 5\n",
      "fullSet, iter: 0 i:94, pairs changed 6\n",
      "fullSet, iter: 0 i:95, pairs changed 6\n",
      "fullSet, iter: 0 i:96, pairs changed 6\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:97, pairs changed 6\n",
      "fullSet, iter: 0 i:98, pairs changed 6\n",
      "fullSet, iter: 0 i:99, pairs changed 6\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:0, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:3, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:4, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:17, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:18, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:25, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:46, pairs changed 0\n",
      "non-bound, iter: 1 i:55, pairs changed 0\n",
      "non-bound, iter: 1 i:94, pairs changed 0\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:0, pairs changed 0\n",
      "fullSet, iter: 2 i:1, pairs changed 0\n",
      "fullSet, iter: 2 i:2, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:3, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:4, pairs changed 0\n",
      "fullSet, iter: 2 i:5, pairs changed 0\n",
      "fullSet, iter: 2 i:6, pairs changed 0\n",
      "fullSet, iter: 2 i:7, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:8, pairs changed 0\n",
      "fullSet, iter: 2 i:9, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:10, pairs changed 0\n",
      "fullSet, iter: 2 i:11, pairs changed 0\n",
      "fullSet, iter: 2 i:12, pairs changed 0\n",
      "fullSet, iter: 2 i:13, pairs changed 0\n",
      "fullSet, iter: 2 i:14, pairs changed 0\n",
      "fullSet, iter: 2 i:15, pairs changed 0\n",
      "fullSet, iter: 2 i:16, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:17, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:18, pairs changed 0\n",
      "fullSet, iter: 2 i:19, pairs changed 0\n",
      "fullSet, iter: 2 i:20, pairs changed 0\n",
      "fullSet, iter: 2 i:21, pairs changed 0\n",
      "fullSet, iter: 2 i:22, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 2 i:23, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:24, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:25, pairs changed 0\n",
      "fullSet, iter: 2 i:26, pairs changed 0\n",
      "fullSet, iter: 2 i:27, pairs changed 0\n",
      "fullSet, iter: 2 i:28, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 2 i:29, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:30, pairs changed 0\n",
      "fullSet, iter: 2 i:31, pairs changed 0\n",
      "fullSet, iter: 2 i:32, pairs changed 0\n",
      "fullSet, iter: 2 i:33, pairs changed 0\n",
      "fullSet, iter: 2 i:34, pairs changed 0\n",
      "fullSet, iter: 2 i:35, pairs changed 0\n",
      "fullSet, iter: 2 i:36, pairs changed 0\n",
      "fullSet, iter: 2 i:37, pairs changed 0\n",
      "fullSet, iter: 2 i:38, pairs changed 0\n",
      "fullSet, iter: 2 i:39, pairs changed 0\n",
      "fullSet, iter: 2 i:40, pairs changed 0\n",
      "fullSet, iter: 2 i:41, pairs changed 0\n",
      "fullSet, iter: 2 i:42, pairs changed 0\n",
      "fullSet, iter: 2 i:43, pairs changed 0\n",
      "fullSet, iter: 2 i:44, pairs changed 0\n",
      "fullSet, iter: 2 i:45, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:46, pairs changed 0\n",
      "fullSet, iter: 2 i:47, pairs changed 0\n",
      "fullSet, iter: 2 i:48, pairs changed 0\n",
      "fullSet, iter: 2 i:49, pairs changed 0\n",
      "fullSet, iter: 2 i:50, pairs changed 0\n",
      "fullSet, iter: 2 i:51, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 2 i:52, pairs changed 0\n",
      "fullSet, iter: 2 i:53, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 2 i:54, pairs changed 0\n",
      "fullSet, iter: 2 i:55, pairs changed 0\n",
      "fullSet, iter: 2 i:56, pairs changed 0\n",
      "fullSet, iter: 2 i:57, pairs changed 0\n",
      "fullSet, iter: 2 i:58, pairs changed 0\n",
      "fullSet, iter: 2 i:59, pairs changed 0\n",
      "fullSet, iter: 2 i:60, pairs changed 0\n",
      "fullSet, iter: 2 i:61, pairs changed 0\n",
      "fullSet, iter: 2 i:62, pairs changed 0\n",
      "fullSet, iter: 2 i:63, pairs changed 0\n",
      "fullSet, iter: 2 i:64, pairs changed 0\n",
      "fullSet, iter: 2 i:65, pairs changed 0\n",
      "fullSet, iter: 2 i:66, pairs changed 0\n",
      "fullSet, iter: 2 i:67, pairs changed 0\n",
      "fullSet, iter: 2 i:68, pairs changed 0\n",
      "fullSet, iter: 2 i:69, pairs changed 0\n",
      "fullSet, iter: 2 i:70, pairs changed 0\n",
      "fullSet, iter: 2 i:71, pairs changed 0\n",
      "fullSet, iter: 2 i:72, pairs changed 0\n",
      "fullSet, iter: 2 i:73, pairs changed 0\n",
      "fullSet, iter: 2 i:74, pairs changed 0\n",
      "fullSet, iter: 2 i:75, pairs changed 0\n",
      "fullSet, iter: 2 i:76, pairs changed 0\n",
      "fullSet, iter: 2 i:77, pairs changed 0\n",
      "fullSet, iter: 2 i:78, pairs changed 0\n",
      "fullSet, iter: 2 i:79, pairs changed 0\n",
      "fullSet, iter: 2 i:80, pairs changed 0\n",
      "fullSet, iter: 2 i:81, pairs changed 0\n",
      "fullSet, iter: 2 i:82, pairs changed 0\n",
      "fullSet, iter: 2 i:83, pairs changed 0\n",
      "fullSet, iter: 2 i:84, pairs changed 0\n",
      "fullSet, iter: 2 i:85, pairs changed 0\n",
      "fullSet, iter: 2 i:86, pairs changed 0\n",
      "fullSet, iter: 2 i:87, pairs changed 0\n",
      "fullSet, iter: 2 i:88, pairs changed 0\n",
      "fullSet, iter: 2 i:89, pairs changed 0\n",
      "fullSet, iter: 2 i:90, pairs changed 0\n",
      "fullSet, iter: 2 i:91, pairs changed 0\n",
      "fullSet, iter: 2 i:92, pairs changed 0\n",
      "fullSet, iter: 2 i:93, pairs changed 0\n",
      "fullSet, iter: 2 i:94, pairs changed 0\n",
      "fullSet, iter: 2 i:95, pairs changed 0\n",
      "fullSet, iter: 2 i:96, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 2 i:97, pairs changed 0\n",
      "fullSet, iter: 2 i:98, pairs changed 0\n",
      "fullSet, iter: 2 i:99, pairs changed 0\n",
      "iteration number: 3\n"
     ]
    }
   ],
   "source": [
    "dataArr, labelArr = loadDataSet('testSet.txt')\n",
    "b, alphas = smoP(dataArr, labelArr, 0.6, 0.001, 40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calcWs(alphas,dataArr,classLabels):\n",
    "    X = mat(dataArr); labelMat = mat(classLabels).transpose()\n",
    "    m,n = shape(X)\n",
    "    w = zeros((n,1))\n",
    "    for i in range(m):\n",
    "        w += multiply(alphas[i]*labelMat[i],X[i,:].T)\n",
    "    return w"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.65307162],\n",
       "       [-0.17196128]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ws = calcWs(alphas, dataArr, labelArr)\n",
    "ws"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[-0.92555695]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datMat = mat(dataArr)\n",
    "datMat[0]*mat(ws) +b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labelArr[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 2.30436336]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datMat[2]*mat(ws) +b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labelArr[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[-1.36706674]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datMat[1] * mat(ws) +b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1.0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labelArr[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "def testRbf(k1=1.3):\n",
    "    dataArr,labelArr = loadDataSet('testSetRBF.txt')\n",
    "    b,alphas = smoP(dataArr, labelArr, 200, 0.0001, 10000, ('rbf', k1)) #C=200 important\n",
    "    datMat=mat(dataArr); labelMat = mat(labelArr).transpose()\n",
    "    svInd=nonzero(alphas.A>0)[0]\n",
    "    sVs=datMat[svInd] #get matrix of only support vectors\n",
    "    labelSV = labelMat[svInd];\n",
    "    print(\"there are %d Support Vectors\" % shape(sVs)[0])\n",
    "    m,n = shape(datMat)\n",
    "    errorCount = 0\n",
    "    for i in range(m):\n",
    "        kernelEval = kernelTrans(sVs,datMat[i,:],('rbf', k1))\n",
    "        predict=kernelEval.T * multiply(labelSV,alphas[svInd]) + b\n",
    "        if sign(predict)!=sign(labelArr[i]): errorCount += 1\n",
    "    print(\"the training error rate is: %f\" % (float(errorCount)/m))\n",
    "    dataArr,labelArr = loadDataSet('testSetRBF2.txt')\n",
    "    errorCount = 0\n",
    "    datMat=mat(dataArr); labelMat = mat(labelArr).transpose()\n",
    "    m,n = shape(datMat)\n",
    "    for i in range(m):\n",
    "        kernelEval = kernelTrans(sVs,datMat[i,:],('rbf', k1))\n",
    "        predict=kernelEval.T * multiply(labelSV,alphas[svInd]) + b\n",
    "        if sign(predict)!=sign(labelArr[i]): errorCount += 1    \n",
    "    print(\"the test error rate is: %f\" % (float(errorCount)/m))  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "L==H\n",
      "fullSet, iter: 0 i:0, pairs changed 0\n",
      "fullSet, iter: 0 i:1, pairs changed 1\n",
      "fullSet, iter: 0 i:2, pairs changed 2\n",
      "fullSet, iter: 0 i:3, pairs changed 3\n",
      "fullSet, iter: 0 i:4, pairs changed 3\n",
      "fullSet, iter: 0 i:5, pairs changed 4\n",
      "fullSet, iter: 0 i:6, pairs changed 4\n",
      "fullSet, iter: 0 i:7, pairs changed 5\n",
      "fullSet, iter: 0 i:8, pairs changed 5\n",
      "fullSet, iter: 0 i:9, pairs changed 5\n",
      "fullSet, iter: 0 i:10, pairs changed 6\n",
      "fullSet, iter: 0 i:11, pairs changed 7\n",
      "fullSet, iter: 0 i:12, pairs changed 7\n",
      "fullSet, iter: 0 i:13, pairs changed 8\n",
      "fullSet, iter: 0 i:14, pairs changed 9\n",
      "fullSet, iter: 0 i:15, pairs changed 10\n",
      "fullSet, iter: 0 i:16, pairs changed 11\n",
      "fullSet, iter: 0 i:17, pairs changed 12\n",
      "fullSet, iter: 0 i:18, pairs changed 13\n",
      "fullSet, iter: 0 i:19, pairs changed 14\n",
      "fullSet, iter: 0 i:20, pairs changed 14\n",
      "fullSet, iter: 0 i:21, pairs changed 15\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:22, pairs changed 15\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:23, pairs changed 15\n",
      "fullSet, iter: 0 i:24, pairs changed 16\n",
      "fullSet, iter: 0 i:25, pairs changed 16\n",
      "fullSet, iter: 0 i:26, pairs changed 17\n",
      "fullSet, iter: 0 i:27, pairs changed 18\n",
      "fullSet, iter: 0 i:28, pairs changed 19\n",
      "fullSet, iter: 0 i:29, pairs changed 20\n",
      "fullSet, iter: 0 i:30, pairs changed 20\n",
      "fullSet, iter: 0 i:31, pairs changed 21\n",
      "fullSet, iter: 0 i:32, pairs changed 21\n",
      "fullSet, iter: 0 i:33, pairs changed 21\n",
      "fullSet, iter: 0 i:34, pairs changed 21\n",
      "fullSet, iter: 0 i:35, pairs changed 21\n",
      "fullSet, iter: 0 i:36, pairs changed 22\n",
      "fullSet, iter: 0 i:37, pairs changed 22\n",
      "fullSet, iter: 0 i:38, pairs changed 22\n",
      "fullSet, iter: 0 i:39, pairs changed 22\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:40, pairs changed 22\n",
      "fullSet, iter: 0 i:41, pairs changed 23\n",
      "L==H\n",
      "fullSet, iter: 0 i:42, pairs changed 23\n",
      "fullSet, iter: 0 i:43, pairs changed 23\n",
      "fullSet, iter: 0 i:44, pairs changed 23\n",
      "fullSet, iter: 0 i:45, pairs changed 24\n",
      "L==H\n",
      "fullSet, iter: 0 i:46, pairs changed 24\n",
      "fullSet, iter: 0 i:47, pairs changed 24\n",
      "L==H\n",
      "fullSet, iter: 0 i:48, pairs changed 24\n",
      "fullSet, iter: 0 i:49, pairs changed 24\n",
      "fullSet, iter: 0 i:50, pairs changed 25\n",
      "fullSet, iter: 0 i:51, pairs changed 25\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:52, pairs changed 25\n",
      "L==H\n",
      "fullSet, iter: 0 i:53, pairs changed 25\n",
      "fullSet, iter: 0 i:54, pairs changed 26\n",
      "fullSet, iter: 0 i:55, pairs changed 26\n",
      "fullSet, iter: 0 i:56, pairs changed 27\n",
      "fullSet, iter: 0 i:57, pairs changed 27\n",
      "fullSet, iter: 0 i:58, pairs changed 27\n",
      "fullSet, iter: 0 i:59, pairs changed 27\n",
      "fullSet, iter: 0 i:60, pairs changed 27\n",
      "fullSet, iter: 0 i:61, pairs changed 27\n",
      "fullSet, iter: 0 i:62, pairs changed 28\n",
      "fullSet, iter: 0 i:63, pairs changed 28\n",
      "fullSet, iter: 0 i:64, pairs changed 28\n",
      "fullSet, iter: 0 i:65, pairs changed 28\n",
      "fullSet, iter: 0 i:66, pairs changed 28\n",
      "fullSet, iter: 0 i:67, pairs changed 28\n",
      "fullSet, iter: 0 i:68, pairs changed 28\n",
      "fullSet, iter: 0 i:69, pairs changed 28\n",
      "fullSet, iter: 0 i:70, pairs changed 28\n",
      "fullSet, iter: 0 i:71, pairs changed 28\n",
      "fullSet, iter: 0 i:72, pairs changed 28\n",
      "fullSet, iter: 0 i:73, pairs changed 28\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:74, pairs changed 28\n",
      "fullSet, iter: 0 i:75, pairs changed 28\n",
      "L==H\n",
      "fullSet, iter: 0 i:76, pairs changed 28\n",
      "fullSet, iter: 0 i:77, pairs changed 28\n",
      "L==H\n",
      "fullSet, iter: 0 i:78, pairs changed 28\n",
      "fullSet, iter: 0 i:79, pairs changed 28\n",
      "fullSet, iter: 0 i:80, pairs changed 28\n",
      "L==H\n",
      "fullSet, iter: 0 i:81, pairs changed 28\n",
      "fullSet, iter: 0 i:82, pairs changed 28\n",
      "fullSet, iter: 0 i:83, pairs changed 28\n",
      "fullSet, iter: 0 i:84, pairs changed 28\n",
      "L==H\n",
      "fullSet, iter: 0 i:85, pairs changed 28\n",
      "fullSet, iter: 0 i:86, pairs changed 28\n",
      "L==H\n",
      "fullSet, iter: 0 i:87, pairs changed 28\n",
      "fullSet, iter: 0 i:88, pairs changed 28\n",
      "fullSet, iter: 0 i:89, pairs changed 28\n",
      "L==H\n",
      "fullSet, iter: 0 i:90, pairs changed 28\n",
      "fullSet, iter: 0 i:91, pairs changed 28\n",
      "L==H\n",
      "fullSet, iter: 0 i:92, pairs changed 28\n",
      "fullSet, iter: 0 i:93, pairs changed 28\n",
      "fullSet, iter: 0 i:94, pairs changed 28\n",
      "fullSet, iter: 0 i:95, pairs changed 28\n",
      "fullSet, iter: 0 i:96, pairs changed 28\n",
      "fullSet, iter: 0 i:97, pairs changed 28\n",
      "fullSet, iter: 0 i:98, pairs changed 28\n",
      "fullSet, iter: 0 i:99, pairs changed 28\n",
      "iteration number: 1\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:0, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:1, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:3, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:10, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:11, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:13, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:14, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:15, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:16, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:17, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:18, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:19, pairs changed 0\n",
      "non-bound, iter: 1 i:21, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:24, pairs changed 0\n",
      "non-bound, iter: 1 i:26, pairs changed 1\n",
      "non-bound, iter: 1 i:27, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:28, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:29, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:31, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:36, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:41, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:42, pairs changed 2\n",
      "non-bound, iter: 1 i:45, pairs changed 3\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:50, pairs changed 3\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:54, pairs changed 3\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:56, pairs changed 3\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:62, pairs changed 3\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:0, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:1, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:3, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:10, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:11, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:13, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:14, pairs changed 0\n",
      "non-bound, iter: 2 i:15, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:16, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:17, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:18, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:19, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:21, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:26, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:27, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:28, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:29, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:31, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:36, pairs changed 1\n",
      "non-bound, iter: 2 i:41, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:42, pairs changed 1\n",
      "non-bound, iter: 2 i:45, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:50, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:54, pairs changed 2\n",
      "non-bound, iter: 2 i:56, pairs changed 3\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:62, pairs changed 3\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:76, pairs changed 3\n",
      "iteration number: 3\n",
      "non-bound, iter: 3 i:0, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:1, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:3, pairs changed 1\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:10, pairs changed 1\n",
      "non-bound, iter: 3 i:11, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:13, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:14, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:16, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:17, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:18, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:19, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:21, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:26, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:27, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:28, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:29, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:31, pairs changed 2\n",
      "non-bound, iter: 3 i:36, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:41, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:42, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:45, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:50, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:54, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:56, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:62, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:76, pairs changed 2\n",
      "j not moving enough\n",
      "non-bound, iter: 3 i:87, pairs changed 2\n",
      "iteration number: 4\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:0, pairs changed 0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j not moving enough\n",
      "non-bound, iter: 4 i:1, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:3, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:10, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:13, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:14, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:16, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:17, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:18, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:19, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:21, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:26, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:27, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:28, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:29, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:31, pairs changed 0\n",
      "non-bound, iter: 4 i:36, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:41, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:42, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:45, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:50, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:54, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:56, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:62, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:76, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 4 i:87, pairs changed 0\n",
      "iteration number: 5\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:0, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:1, pairs changed 0\n",
      "fullSet, iter: 5 i:2, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:3, pairs changed 0\n",
      "fullSet, iter: 5 i:4, pairs changed 0\n",
      "fullSet, iter: 5 i:5, pairs changed 0\n",
      "fullSet, iter: 5 i:6, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:7, pairs changed 0\n",
      "fullSet, iter: 5 i:8, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:9, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:10, pairs changed 0\n",
      "fullSet, iter: 5 i:11, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:12, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:13, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:14, pairs changed 0\n",
      "fullSet, iter: 5 i:15, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:16, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:17, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:18, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:19, pairs changed 0\n",
      "fullSet, iter: 5 i:20, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:21, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:22, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:23, pairs changed 0\n",
      "fullSet, iter: 5 i:24, pairs changed 0\n",
      "fullSet, iter: 5 i:25, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:26, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:27, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:28, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:29, pairs changed 0\n",
      "fullSet, iter: 5 i:30, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:31, pairs changed 0\n",
      "fullSet, iter: 5 i:32, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:33, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:34, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:35, pairs changed 0\n",
      "fullSet, iter: 5 i:36, pairs changed 0\n",
      "fullSet, iter: 5 i:37, pairs changed 0\n",
      "fullSet, iter: 5 i:38, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:39, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:40, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:41, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:42, pairs changed 0\n",
      "fullSet, iter: 5 i:43, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:44, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:45, pairs changed 0\n",
      "fullSet, iter: 5 i:46, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:47, pairs changed 0\n",
      "fullSet, iter: 5 i:48, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:49, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:50, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:51, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:52, pairs changed 0\n",
      "fullSet, iter: 5 i:53, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:54, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:55, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:56, pairs changed 0\n",
      "fullSet, iter: 5 i:57, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 5 i:58, pairs changed 0\n",
      "fullSet, iter: 5 i:59, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:60, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:61, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:62, pairs changed 0\n",
      "fullSet, iter: 5 i:63, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:64, pairs changed 0\n",
      "fullSet, iter: 5 i:65, pairs changed 0\n",
      "fullSet, iter: 5 i:66, pairs changed 0\n",
      "fullSet, iter: 5 i:67, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:68, pairs changed 0\n",
      "fullSet, iter: 5 i:69, pairs changed 0\n",
      "fullSet, iter: 5 i:70, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:71, pairs changed 0\n",
      "fullSet, iter: 5 i:72, pairs changed 0\n",
      "fullSet, iter: 5 i:73, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:74, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:75, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:76, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:77, pairs changed 0\n",
      "fullSet, iter: 5 i:78, pairs changed 0\n",
      "fullSet, iter: 5 i:79, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:80, pairs changed 0\n",
      "fullSet, iter: 5 i:81, pairs changed 0\n",
      "fullSet, iter: 5 i:82, pairs changed 0\n",
      "fullSet, iter: 5 i:83, pairs changed 0\n",
      "fullSet, iter: 5 i:84, pairs changed 0\n",
      "fullSet, iter: 5 i:85, pairs changed 0\n",
      "fullSet, iter: 5 i:86, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:87, pairs changed 0\n",
      "fullSet, iter: 5 i:88, pairs changed 0\n",
      "fullSet, iter: 5 i:89, pairs changed 0\n",
      "fullSet, iter: 5 i:90, pairs changed 0\n",
      "fullSet, iter: 5 i:91, pairs changed 0\n",
      "fullSet, iter: 5 i:92, pairs changed 0\n",
      "fullSet, iter: 5 i:93, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 5 i:94, pairs changed 0\n",
      "fullSet, iter: 5 i:95, pairs changed 0\n",
      "fullSet, iter: 5 i:96, pairs changed 0\n",
      "fullSet, iter: 5 i:97, pairs changed 0\n",
      "fullSet, iter: 5 i:98, pairs changed 0\n",
      "fullSet, iter: 5 i:99, pairs changed 0\n",
      "iteration number: 6\n",
      "there are 26 Support Vectors\n",
      "the training error rate is: 0.090000\n",
      "the test error rate is: 0.180000\n"
     ]
    }
   ],
   "source": [
    "testRbf()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "def img2vector(filename):\n",
    "    returnVect = zeros((1,1024))\n",
    "    fr = open(filename)\n",
    "    for i in range(32):\n",
    "        lineStr = fr.readline()\n",
    "        for j in range(32):\n",
    "            returnVect[0,32*i+j] = int(lineStr[j])\n",
    "    return returnVect\n",
    "\n",
    "def loadImages(dirName):\n",
    "    from os import listdir\n",
    "    hwLabels = []\n",
    "    trainingFileList = listdir(dirName)           #load the training set\n",
    "    m = len(trainingFileList)\n",
    "    trainingMat = zeros((m,1024))\n",
    "    for i in range(m):\n",
    "        fileNameStr = trainingFileList[i]\n",
    "        fileStr = fileNameStr.split('.')[0]     #take off .txt\n",
    "        classNumStr = int(fileStr.split('_')[0])\n",
    "        if classNumStr == 9: hwLabels.append(-1)\n",
    "        else: hwLabels.append(1)\n",
    "        trainingMat[i,:] = img2vector('%s/%s' % (dirName, fileNameStr))\n",
    "    return trainingMat, hwLabels    \n",
    "\n",
    "def testDigits(kTup=('rbf', 10)):\n",
    "    dataArr,labelArr = loadImages('trainingDigits')\n",
    "    b,alphas = smoP(dataArr, labelArr, 200, 0.0001, 10000, kTup)\n",
    "    datMat=mat(dataArr); labelMat = mat(labelArr).transpose()\n",
    "    svInd=nonzero(alphas.A>0)[0]\n",
    "    sVs=datMat[svInd] \n",
    "    labelSV = labelMat[svInd];\n",
    "    print(\"there are %d Support Vectors\" % shape(sVs)[0])\n",
    "    m,n = shape(datMat)\n",
    "    errorCount = 0\n",
    "    for i in range(m):\n",
    "        kernelEval = kernelTrans(sVs,datMat[i,:],kTup)\n",
    "        predict=kernelEval.T * multiply(labelSV,alphas[svInd]) + b\n",
    "        if sign(predict)!=sign(labelArr[i]): errorCount += 1\n",
    "    print(\"the training error rate is: %f\" % (float(errorCount)/m))\n",
    "    dataArr,labelArr = loadImages('testDigits')\n",
    "    errorCount = 0\n",
    "    datMat=mat(dataArr); labelMat = mat(labelArr).transpose()\n",
    "    m,n = shape(datMat)\n",
    "    for i in range(m):\n",
    "        kernelEval = kernelTrans(sVs,datMat[i,:],kTup)\n",
    "        predict=kernelEval.T * multiply(labelSV,alphas[svInd]) + b\n",
    "        if sign(predict)!=sign(labelArr[i]): errorCount += 1    \n",
    "    print(\"the test error rate is: %f\" % (float(errorCount)/m)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "L==H\n",
      "fullSet, iter: 0 i:0, pairs changed 0\n",
      "fullSet, iter: 0 i:1, pairs changed 1\n",
      "fullSet, iter: 0 i:2, pairs changed 2\n",
      "fullSet, iter: 0 i:3, pairs changed 3\n",
      "fullSet, iter: 0 i:4, pairs changed 3\n",
      "fullSet, iter: 0 i:5, pairs changed 4\n",
      "fullSet, iter: 0 i:6, pairs changed 5\n",
      "fullSet, iter: 0 i:7, pairs changed 6\n",
      "fullSet, iter: 0 i:8, pairs changed 6\n",
      "fullSet, iter: 0 i:9, pairs changed 6\n",
      "fullSet, iter: 0 i:10, pairs changed 6\n",
      "fullSet, iter: 0 i:11, pairs changed 6\n",
      "fullSet, iter: 0 i:12, pairs changed 7\n",
      "fullSet, iter: 0 i:13, pairs changed 8\n",
      "fullSet, iter: 0 i:14, pairs changed 9\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:15, pairs changed 9\n",
      "fullSet, iter: 0 i:16, pairs changed 10\n",
      "fullSet, iter: 0 i:17, pairs changed 10\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:18, pairs changed 10\n",
      "fullSet, iter: 0 i:19, pairs changed 11\n",
      "fullSet, iter: 0 i:20, pairs changed 12\n",
      "fullSet, iter: 0 i:21, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:22, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:23, pairs changed 13\n",
      "fullSet, iter: 0 i:24, pairs changed 13\n",
      "fullSet, iter: 0 i:25, pairs changed 13\n",
      "fullSet, iter: 0 i:26, pairs changed 13\n",
      "fullSet, iter: 0 i:27, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:28, pairs changed 13\n",
      "fullSet, iter: 0 i:29, pairs changed 13\n",
      "fullSet, iter: 0 i:30, pairs changed 13\n",
      "fullSet, iter: 0 i:31, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:32, pairs changed 13\n",
      "fullSet, iter: 0 i:33, pairs changed 13\n",
      "fullSet, iter: 0 i:34, pairs changed 13\n",
      "fullSet, iter: 0 i:35, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:36, pairs changed 13\n",
      "fullSet, iter: 0 i:37, pairs changed 13\n",
      "fullSet, iter: 0 i:38, pairs changed 13\n",
      "fullSet, iter: 0 i:39, pairs changed 13\n",
      "fullSet, iter: 0 i:40, pairs changed 13\n",
      "fullSet, iter: 0 i:41, pairs changed 13\n",
      "fullSet, iter: 0 i:42, pairs changed 13\n",
      "fullSet, iter: 0 i:43, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:44, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:45, pairs changed 13\n",
      "fullSet, iter: 0 i:46, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:47, pairs changed 13\n",
      "fullSet, iter: 0 i:48, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:49, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:50, pairs changed 13\n",
      "fullSet, iter: 0 i:51, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:52, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:53, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:54, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:55, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:56, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:57, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:58, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:59, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:60, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:61, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:62, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:63, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:64, pairs changed 13\n",
      "fullSet, iter: 0 i:65, pairs changed 13\n",
      "fullSet, iter: 0 i:66, pairs changed 13\n",
      "fullSet, iter: 0 i:67, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:68, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:69, pairs changed 13\n",
      "fullSet, iter: 0 i:70, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:71, pairs changed 13\n",
      "fullSet, iter: 0 i:72, pairs changed 13\n",
      "fullSet, iter: 0 i:73, pairs changed 13\n",
      "fullSet, iter: 0 i:74, pairs changed 13\n",
      "fullSet, iter: 0 i:75, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:76, pairs changed 13\n",
      "fullSet, iter: 0 i:77, pairs changed 13\n",
      "fullSet, iter: 0 i:78, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:79, pairs changed 13\n",
      "fullSet, iter: 0 i:80, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:81, pairs changed 13\n",
      "fullSet, iter: 0 i:82, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:83, pairs changed 13\n",
      "fullSet, iter: 0 i:84, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:85, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:86, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:87, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:88, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:89, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:90, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:91, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:92, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:93, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:94, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:95, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:96, pairs changed 13\n",
      "fullSet, iter: 0 i:97, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:98, pairs changed 13\n",
      "fullSet, iter: 0 i:99, pairs changed 13\n",
      "fullSet, iter: 0 i:100, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:101, pairs changed 13\n",
      "fullSet, iter: 0 i:102, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:103, pairs changed 13\n",
      "fullSet, iter: 0 i:104, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:105, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:106, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:107, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:108, pairs changed 13\n",
      "fullSet, iter: 0 i:109, pairs changed 13\n",
      "fullSet, iter: 0 i:110, pairs changed 13\n",
      "fullSet, iter: 0 i:111, pairs changed 13\n",
      "fullSet, iter: 0 i:112, pairs changed 13\n",
      "fullSet, iter: 0 i:113, pairs changed 13\n",
      "fullSet, iter: 0 i:114, pairs changed 13\n",
      "fullSet, iter: 0 i:115, pairs changed 13\n",
      "fullSet, iter: 0 i:116, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:117, pairs changed 13\n",
      "fullSet, iter: 0 i:118, pairs changed 13\n",
      "fullSet, iter: 0 i:119, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:120, pairs changed 13\n",
      "fullSet, iter: 0 i:121, pairs changed 13\n",
      "fullSet, iter: 0 i:122, pairs changed 13\n",
      "fullSet, iter: 0 i:123, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:124, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:125, pairs changed 13\n",
      "fullSet, iter: 0 i:126, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:127, pairs changed 13\n",
      "fullSet, iter: 0 i:128, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:129, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:130, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:131, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:132, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:133, pairs changed 13\n",
      "fullSet, iter: 0 i:134, pairs changed 13\n",
      "fullSet, iter: 0 i:135, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:136, pairs changed 13\n",
      "fullSet, iter: 0 i:137, pairs changed 13\n",
      "fullSet, iter: 0 i:138, pairs changed 13\n",
      "fullSet, iter: 0 i:139, pairs changed 13\n",
      "fullSet, iter: 0 i:140, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:141, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:142, pairs changed 13\n",
      "fullSet, iter: 0 i:143, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:144, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:145, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:146, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:147, pairs changed 13\n",
      "fullSet, iter: 0 i:148, pairs changed 13\n",
      "fullSet, iter: 0 i:149, pairs changed 13\n",
      "fullSet, iter: 0 i:150, pairs changed 13\n",
      "fullSet, iter: 0 i:151, pairs changed 13\n",
      "fullSet, iter: 0 i:152, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:153, pairs changed 13\n",
      "fullSet, iter: 0 i:154, pairs changed 13\n",
      "fullSet, iter: 0 i:155, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:156, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:157, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:158, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:159, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:160, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:161, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:162, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:163, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:164, pairs changed 13\n",
      "fullSet, iter: 0 i:165, pairs changed 13\n",
      "fullSet, iter: 0 i:166, pairs changed 13\n",
      "fullSet, iter: 0 i:167, pairs changed 13\n",
      "fullSet, iter: 0 i:168, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:169, pairs changed 13\n",
      "fullSet, iter: 0 i:170, pairs changed 13\n",
      "fullSet, iter: 0 i:171, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:172, pairs changed 13\n",
      "fullSet, iter: 0 i:173, pairs changed 13\n",
      "fullSet, iter: 0 i:174, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:175, pairs changed 13\n",
      "fullSet, iter: 0 i:176, pairs changed 13\n",
      "fullSet, iter: 0 i:177, pairs changed 13\n",
      "fullSet, iter: 0 i:178, pairs changed 13\n",
      "fullSet, iter: 0 i:179, pairs changed 13\n",
      "fullSet, iter: 0 i:180, pairs changed 13\n",
      "fullSet, iter: 0 i:181, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:182, pairs changed 13\n",
      "fullSet, iter: 0 i:183, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:184, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:185, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:186, pairs changed 13\n",
      "fullSet, iter: 0 i:187, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:188, pairs changed 13\n",
      "L==H\n",
      "fullSet, iter: 0 i:189, pairs changed 13\n",
      "fullSet, iter: 0 i:190, pairs changed 13\n",
      "fullSet, iter: 0 i:191, pairs changed 13\n",
      "fullSet, iter: 0 i:192, pairs changed 13\n",
      "fullSet, iter: 0 i:193, pairs changed 13\n",
      "fullSet, iter: 0 i:194, pairs changed 13\n",
      "fullSet, iter: 0 i:195, pairs changed 13\n",
      "fullSet, iter: 0 i:196, pairs changed 13\n",
      "fullSet, iter: 0 i:197, pairs changed 13\n",
      "fullSet, iter: 0 i:198, pairs changed 14\n",
      "fullSet, iter: 0 i:199, pairs changed 15\n",
      "fullSet, iter: 0 i:200, pairs changed 16\n",
      "fullSet, iter: 0 i:201, pairs changed 17\n",
      "fullSet, iter: 0 i:202, pairs changed 18\n",
      "fullSet, iter: 0 i:203, pairs changed 19\n",
      "fullSet, iter: 0 i:204, pairs changed 20\n",
      "fullSet, iter: 0 i:205, pairs changed 21\n",
      "fullSet, iter: 0 i:206, pairs changed 21\n",
      "fullSet, iter: 0 i:207, pairs changed 22\n",
      "fullSet, iter: 0 i:208, pairs changed 23\n",
      "fullSet, iter: 0 i:209, pairs changed 24\n",
      "fullSet, iter: 0 i:210, pairs changed 25\n",
      "fullSet, iter: 0 i:211, pairs changed 26\n",
      "fullSet, iter: 0 i:212, pairs changed 26\n",
      "fullSet, iter: 0 i:213, pairs changed 26\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:214, pairs changed 26\n",
      "fullSet, iter: 0 i:215, pairs changed 27\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:216, pairs changed 27\n",
      "fullSet, iter: 0 i:217, pairs changed 27\n",
      "fullSet, iter: 0 i:218, pairs changed 28\n",
      "fullSet, iter: 0 i:219, pairs changed 28\n",
      "fullSet, iter: 0 i:220, pairs changed 28\n",
      "fullSet, iter: 0 i:221, pairs changed 28\n",
      "fullSet, iter: 0 i:222, pairs changed 29\n",
      "fullSet, iter: 0 i:223, pairs changed 29\n",
      "fullSet, iter: 0 i:224, pairs changed 29\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:225, pairs changed 29\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:226, pairs changed 29\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:227, pairs changed 29\n",
      "fullSet, iter: 0 i:228, pairs changed 29\n",
      "fullSet, iter: 0 i:229, pairs changed 29\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:230, pairs changed 29\n",
      "fullSet, iter: 0 i:231, pairs changed 29\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:232, pairs changed 29\n",
      "fullSet, iter: 0 i:233, pairs changed 30\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:234, pairs changed 30\n",
      "fullSet, iter: 0 i:235, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:236, pairs changed 31\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:237, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:238, pairs changed 31\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:239, pairs changed 31\n",
      "fullSet, iter: 0 i:240, pairs changed 31\n",
      "fullSet, iter: 0 i:241, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:242, pairs changed 31\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:243, pairs changed 31\n",
      "j not moving enough\n",
      "fullSet, iter: 0 i:244, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:245, pairs changed 31\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j not moving enough\n",
      "fullSet, iter: 0 i:246, pairs changed 31\n",
      "fullSet, iter: 0 i:247, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:248, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:249, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:250, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:251, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:252, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:253, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:254, pairs changed 31\n",
      "fullSet, iter: 0 i:255, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:256, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:257, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:258, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:259, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:260, pairs changed 31\n",
      "fullSet, iter: 0 i:261, pairs changed 31\n",
      "fullSet, iter: 0 i:262, pairs changed 31\n",
      "fullSet, iter: 0 i:263, pairs changed 31\n",
      "fullSet, iter: 0 i:264, pairs changed 31\n",
      "fullSet, iter: 0 i:265, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:266, pairs changed 31\n",
      "fullSet, iter: 0 i:267, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:268, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:269, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:270, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:271, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:272, pairs changed 31\n",
      "fullSet, iter: 0 i:273, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:274, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:275, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:276, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:277, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:278, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:279, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:280, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:281, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:282, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:283, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:284, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:285, pairs changed 31\n",
      "fullSet, iter: 0 i:286, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:287, pairs changed 31\n",
      "fullSet, iter: 0 i:288, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:289, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:290, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:291, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:292, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:293, pairs changed 31\n",
      "fullSet, iter: 0 i:294, pairs changed 31\n",
      "fullSet, iter: 0 i:295, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:296, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:297, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:298, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:299, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:300, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:301, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:302, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:303, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:304, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:305, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:306, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:307, pairs changed 31\n",
      "fullSet, iter: 0 i:308, pairs changed 31\n",
      "fullSet, iter: 0 i:309, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:310, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:311, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:312, pairs changed 31\n",
      "fullSet, iter: 0 i:313, pairs changed 31\n",
      "fullSet, iter: 0 i:314, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:315, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:316, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:317, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:318, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:319, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:320, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:321, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:322, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:323, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:324, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:325, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:326, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:327, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:328, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:329, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:330, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:331, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:332, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:333, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:334, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:335, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:336, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:337, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:338, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:339, pairs changed 31\n",
      "fullSet, iter: 0 i:340, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:341, pairs changed 31\n",
      "fullSet, iter: 0 i:342, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:343, pairs changed 31\n",
      "fullSet, iter: 0 i:344, pairs changed 31\n",
      "fullSet, iter: 0 i:345, pairs changed 31\n",
      "fullSet, iter: 0 i:346, pairs changed 31\n",
      "fullSet, iter: 0 i:347, pairs changed 31\n",
      "fullSet, iter: 0 i:348, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:349, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:350, pairs changed 31\n",
      "fullSet, iter: 0 i:351, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:352, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:353, pairs changed 31\n",
      "fullSet, iter: 0 i:354, pairs changed 31\n",
      "fullSet, iter: 0 i:355, pairs changed 31\n",
      "fullSet, iter: 0 i:356, pairs changed 31\n",
      "fullSet, iter: 0 i:357, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:358, pairs changed 31\n",
      "fullSet, iter: 0 i:359, pairs changed 31\n",
      "fullSet, iter: 0 i:360, pairs changed 31\n",
      "fullSet, iter: 0 i:361, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:362, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:363, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:364, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:365, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:366, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:367, pairs changed 31\n",
      "fullSet, iter: 0 i:368, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:369, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:370, pairs changed 31\n",
      "fullSet, iter: 0 i:371, pairs changed 31\n",
      "fullSet, iter: 0 i:372, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:373, pairs changed 31\n",
      "fullSet, iter: 0 i:374, pairs changed 31\n",
      "fullSet, iter: 0 i:375, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:376, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:377, pairs changed 31\n",
      "fullSet, iter: 0 i:378, pairs changed 31\n",
      "fullSet, iter: 0 i:379, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:380, pairs changed 31\n",
      "fullSet, iter: 0 i:381, pairs changed 31\n",
      "fullSet, iter: 0 i:382, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:383, pairs changed 31\n",
      "fullSet, iter: 0 i:384, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:385, pairs changed 31\n",
      "fullSet, iter: 0 i:386, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:387, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:388, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:389, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:390, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:391, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:392, pairs changed 31\n",
      "fullSet, iter: 0 i:393, pairs changed 31\n",
      "fullSet, iter: 0 i:394, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:395, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:396, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:397, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:398, pairs changed 31\n",
      "L==H\n",
      "fullSet, iter: 0 i:399, pairs changed 31\n",
      "fullSet, iter: 0 i:400, pairs changed 31\n",
      "fullSet, iter: 0 i:401, pairs changed 32\n",
      "iteration number: 1\n",
      "non-bound, iter: 1 i:1, pairs changed 1\n",
      "non-bound, iter: 1 i:3, pairs changed 2\n",
      "non-bound, iter: 1 i:5, pairs changed 3\n",
      "non-bound, iter: 1 i:7, pairs changed 4\n",
      "non-bound, iter: 1 i:13, pairs changed 5\n",
      "non-bound, iter: 1 i:14, pairs changed 6\n",
      "non-bound, iter: 1 i:16, pairs changed 7\n",
      "non-bound, iter: 1 i:19, pairs changed 8\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:20, pairs changed 8\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:21, pairs changed 8\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:63, pairs changed 8\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:85, pairs changed 8\n",
      "non-bound, iter: 1 i:87, pairs changed 9\n",
      "non-bound, iter: 1 i:105, pairs changed 10\n",
      "non-bound, iter: 1 i:117, pairs changed 11\n",
      "non-bound, iter: 1 i:125, pairs changed 12\n",
      "non-bound, iter: 1 i:127, pairs changed 13\n",
      "non-bound, iter: 1 i:130, pairs changed 14\n",
      "non-bound, iter: 1 i:162, pairs changed 15\n",
      "non-bound, iter: 1 i:172, pairs changed 16\n",
      "non-bound, iter: 1 i:198, pairs changed 17\n",
      "non-bound, iter: 1 i:199, pairs changed 18\n",
      "non-bound, iter: 1 i:200, pairs changed 19\n",
      "non-bound, iter: 1 i:203, pairs changed 20\n",
      "non-bound, iter: 1 i:204, pairs changed 21\n",
      "non-bound, iter: 1 i:205, pairs changed 22\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:207, pairs changed 22\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:208, pairs changed 22\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:209, pairs changed 22\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:210, pairs changed 22\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:211, pairs changed 22\n",
      "non-bound, iter: 1 i:215, pairs changed 23\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:218, pairs changed 23\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j not moving enough\n",
      "non-bound, iter: 1 i:222, pairs changed 23\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:233, pairs changed 23\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:235, pairs changed 23\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:317, pairs changed 23\n",
      "j not moving enough\n",
      "non-bound, iter: 1 i:401, pairs changed 23\n",
      "iteration number: 2\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:1, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:3, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:5, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:7, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:13, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:14, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:16, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:20, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:21, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:63, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:85, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:87, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:105, pairs changed 0\n",
      "non-bound, iter: 2 i:117, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:125, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:127, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:130, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:162, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:172, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:185, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:199, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:200, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:203, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:205, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:207, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:208, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:209, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:210, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:211, pairs changed 0\n",
      "non-bound, iter: 2 i:215, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:218, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:222, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:233, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:235, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:249, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:254, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:284, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:287, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:305, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:311, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:317, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:319, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:322, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:323, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:330, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:332, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:337, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:343, pairs changed 0\n",
      "j not moving enough\n",
      "non-bound, iter: 2 i:401, pairs changed 0\n",
      "iteration number: 3\n",
      "fullSet, iter: 3 i:0, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:1, pairs changed 0\n",
      "fullSet, iter: 3 i:2, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:3, pairs changed 0\n",
      "fullSet, iter: 3 i:4, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:5, pairs changed 0\n",
      "fullSet, iter: 3 i:6, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:7, pairs changed 0\n",
      "fullSet, iter: 3 i:8, pairs changed 0\n",
      "fullSet, iter: 3 i:9, pairs changed 0\n",
      "fullSet, iter: 3 i:10, pairs changed 0\n",
      "fullSet, iter: 3 i:11, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:12, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:13, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:14, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:15, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:16, pairs changed 0\n",
      "fullSet, iter: 3 i:17, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:18, pairs changed 0\n",
      "fullSet, iter: 3 i:19, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:20, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:21, pairs changed 0\n",
      "fullSet, iter: 3 i:22, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:23, pairs changed 0\n",
      "fullSet, iter: 3 i:24, pairs changed 0\n",
      "fullSet, iter: 3 i:25, pairs changed 0\n",
      "fullSet, iter: 3 i:26, pairs changed 0\n",
      "fullSet, iter: 3 i:27, pairs changed 0\n",
      "fullSet, iter: 3 i:28, pairs changed 0\n",
      "fullSet, iter: 3 i:29, pairs changed 0\n",
      "fullSet, iter: 3 i:30, pairs changed 0\n",
      "fullSet, iter: 3 i:31, pairs changed 0\n",
      "fullSet, iter: 3 i:32, pairs changed 0\n",
      "fullSet, iter: 3 i:33, pairs changed 0\n",
      "fullSet, iter: 3 i:34, pairs changed 0\n",
      "fullSet, iter: 3 i:35, pairs changed 0\n",
      "fullSet, iter: 3 i:36, pairs changed 0\n",
      "fullSet, iter: 3 i:37, pairs changed 0\n",
      "fullSet, iter: 3 i:38, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:39, pairs changed 0\n",
      "fullSet, iter: 3 i:40, pairs changed 0\n",
      "fullSet, iter: 3 i:41, pairs changed 0\n",
      "fullSet, iter: 3 i:42, pairs changed 0\n",
      "fullSet, iter: 3 i:43, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:44, pairs changed 0\n",
      "fullSet, iter: 3 i:45, pairs changed 0\n",
      "fullSet, iter: 3 i:46, pairs changed 0\n",
      "fullSet, iter: 3 i:47, pairs changed 0\n",
      "fullSet, iter: 3 i:48, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:49, pairs changed 0\n",
      "fullSet, iter: 3 i:50, pairs changed 0\n",
      "fullSet, iter: 3 i:51, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:52, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:53, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:54, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:55, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:56, pairs changed 0\n",
      "fullSet, iter: 3 i:57, pairs changed 0\n",
      "fullSet, iter: 3 i:58, pairs changed 0\n",
      "fullSet, iter: 3 i:59, pairs changed 0\n",
      "fullSet, iter: 3 i:60, pairs changed 0\n",
      "fullSet, iter: 3 i:61, pairs changed 0\n",
      "fullSet, iter: 3 i:62, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:63, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:64, pairs changed 0\n",
      "fullSet, iter: 3 i:65, pairs changed 0\n",
      "fullSet, iter: 3 i:66, pairs changed 0\n",
      "fullSet, iter: 3 i:67, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:68, pairs changed 0\n",
      "fullSet, iter: 3 i:69, pairs changed 0\n",
      "fullSet, iter: 3 i:70, pairs changed 0\n",
      "fullSet, iter: 3 i:71, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:72, pairs changed 0\n",
      "fullSet, iter: 3 i:73, pairs changed 0\n",
      "fullSet, iter: 3 i:74, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:75, pairs changed 0\n",
      "fullSet, iter: 3 i:76, pairs changed 0\n",
      "fullSet, iter: 3 i:77, pairs changed 0\n",
      "fullSet, iter: 3 i:78, pairs changed 0\n",
      "fullSet, iter: 3 i:79, pairs changed 0\n",
      "fullSet, iter: 3 i:80, pairs changed 0\n",
      "fullSet, iter: 3 i:81, pairs changed 0\n",
      "fullSet, iter: 3 i:82, pairs changed 0\n",
      "fullSet, iter: 3 i:83, pairs changed 0\n",
      "fullSet, iter: 3 i:84, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:85, pairs changed 0\n",
      "fullSet, iter: 3 i:86, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:87, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:88, pairs changed 0\n",
      "fullSet, iter: 3 i:89, pairs changed 0\n",
      "fullSet, iter: 3 i:90, pairs changed 0\n",
      "fullSet, iter: 3 i:91, pairs changed 0\n",
      "fullSet, iter: 3 i:92, pairs changed 0\n",
      "fullSet, iter: 3 i:93, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:94, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:95, pairs changed 0\n",
      "fullSet, iter: 3 i:96, pairs changed 0\n",
      "fullSet, iter: 3 i:97, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:98, pairs changed 0\n",
      "fullSet, iter: 3 i:99, pairs changed 0\n",
      "fullSet, iter: 3 i:100, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:101, pairs changed 0\n",
      "fullSet, iter: 3 i:102, pairs changed 0\n",
      "fullSet, iter: 3 i:103, pairs changed 0\n",
      "fullSet, iter: 3 i:104, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:105, pairs changed 0\n",
      "fullSet, iter: 3 i:106, pairs changed 0\n",
      "fullSet, iter: 3 i:107, pairs changed 0\n",
      "fullSet, iter: 3 i:108, pairs changed 0\n",
      "fullSet, iter: 3 i:109, pairs changed 0\n",
      "fullSet, iter: 3 i:110, pairs changed 0\n",
      "fullSet, iter: 3 i:111, pairs changed 0\n",
      "fullSet, iter: 3 i:112, pairs changed 0\n",
      "fullSet, iter: 3 i:113, pairs changed 0\n",
      "fullSet, iter: 3 i:114, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:115, pairs changed 0\n",
      "fullSet, iter: 3 i:116, pairs changed 0\n",
      "fullSet, iter: 3 i:117, pairs changed 0\n",
      "fullSet, iter: 3 i:118, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:119, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:120, pairs changed 0\n",
      "fullSet, iter: 3 i:121, pairs changed 0\n",
      "fullSet, iter: 3 i:122, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:123, pairs changed 0\n",
      "fullSet, iter: 3 i:124, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:125, pairs changed 0\n",
      "fullSet, iter: 3 i:126, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:127, pairs changed 0\n",
      "fullSet, iter: 3 i:128, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:129, pairs changed 0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j not moving enough\n",
      "fullSet, iter: 3 i:130, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:131, pairs changed 0\n",
      "fullSet, iter: 3 i:132, pairs changed 0\n",
      "fullSet, iter: 3 i:133, pairs changed 0\n",
      "fullSet, iter: 3 i:134, pairs changed 0\n",
      "fullSet, iter: 3 i:135, pairs changed 0\n",
      "fullSet, iter: 3 i:136, pairs changed 0\n",
      "fullSet, iter: 3 i:137, pairs changed 0\n",
      "fullSet, iter: 3 i:138, pairs changed 0\n",
      "fullSet, iter: 3 i:139, pairs changed 0\n",
      "fullSet, iter: 3 i:140, pairs changed 0\n",
      "fullSet, iter: 3 i:141, pairs changed 0\n",
      "fullSet, iter: 3 i:142, pairs changed 0\n",
      "fullSet, iter: 3 i:143, pairs changed 0\n",
      "fullSet, iter: 3 i:144, pairs changed 0\n",
      "fullSet, iter: 3 i:145, pairs changed 0\n",
      "fullSet, iter: 3 i:146, pairs changed 0\n",
      "fullSet, iter: 3 i:147, pairs changed 0\n",
      "fullSet, iter: 3 i:148, pairs changed 0\n",
      "fullSet, iter: 3 i:149, pairs changed 0\n",
      "fullSet, iter: 3 i:150, pairs changed 0\n",
      "fullSet, iter: 3 i:151, pairs changed 0\n",
      "fullSet, iter: 3 i:152, pairs changed 0\n",
      "fullSet, iter: 3 i:153, pairs changed 0\n",
      "fullSet, iter: 3 i:154, pairs changed 0\n",
      "fullSet, iter: 3 i:155, pairs changed 0\n",
      "fullSet, iter: 3 i:156, pairs changed 0\n",
      "fullSet, iter: 3 i:157, pairs changed 0\n",
      "fullSet, iter: 3 i:158, pairs changed 0\n",
      "fullSet, iter: 3 i:159, pairs changed 0\n",
      "fullSet, iter: 3 i:160, pairs changed 0\n",
      "fullSet, iter: 3 i:161, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:162, pairs changed 0\n",
      "fullSet, iter: 3 i:163, pairs changed 0\n",
      "fullSet, iter: 3 i:164, pairs changed 0\n",
      "fullSet, iter: 3 i:165, pairs changed 0\n",
      "fullSet, iter: 3 i:166, pairs changed 0\n",
      "fullSet, iter: 3 i:167, pairs changed 0\n",
      "fullSet, iter: 3 i:168, pairs changed 0\n",
      "fullSet, iter: 3 i:169, pairs changed 0\n",
      "fullSet, iter: 3 i:170, pairs changed 0\n",
      "fullSet, iter: 3 i:171, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:172, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:173, pairs changed 0\n",
      "fullSet, iter: 3 i:174, pairs changed 0\n",
      "fullSet, iter: 3 i:175, pairs changed 0\n",
      "fullSet, iter: 3 i:176, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:177, pairs changed 0\n",
      "fullSet, iter: 3 i:178, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:179, pairs changed 0\n",
      "fullSet, iter: 3 i:180, pairs changed 0\n",
      "fullSet, iter: 3 i:181, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:182, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:183, pairs changed 0\n",
      "fullSet, iter: 3 i:184, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:185, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:186, pairs changed 0\n",
      "fullSet, iter: 3 i:187, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:188, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:189, pairs changed 0\n",
      "fullSet, iter: 3 i:190, pairs changed 0\n",
      "fullSet, iter: 3 i:191, pairs changed 0\n",
      "fullSet, iter: 3 i:192, pairs changed 0\n",
      "fullSet, iter: 3 i:193, pairs changed 0\n",
      "fullSet, iter: 3 i:194, pairs changed 0\n",
      "fullSet, iter: 3 i:195, pairs changed 0\n",
      "fullSet, iter: 3 i:196, pairs changed 0\n",
      "fullSet, iter: 3 i:197, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:198, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:199, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:200, pairs changed 0\n",
      "fullSet, iter: 3 i:201, pairs changed 0\n",
      "fullSet, iter: 3 i:202, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:203, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:204, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:205, pairs changed 0\n",
      "fullSet, iter: 3 i:206, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:207, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:208, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:209, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:210, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:211, pairs changed 0\n",
      "fullSet, iter: 3 i:212, pairs changed 0\n",
      "fullSet, iter: 3 i:213, pairs changed 0\n",
      "fullSet, iter: 3 i:214, pairs changed 0\n",
      "fullSet, iter: 3 i:215, pairs changed 0\n",
      "fullSet, iter: 3 i:216, pairs changed 0\n",
      "fullSet, iter: 3 i:217, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:218, pairs changed 0\n",
      "fullSet, iter: 3 i:219, pairs changed 0\n",
      "fullSet, iter: 3 i:220, pairs changed 0\n",
      "fullSet, iter: 3 i:221, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:222, pairs changed 0\n",
      "fullSet, iter: 3 i:223, pairs changed 0\n",
      "fullSet, iter: 3 i:224, pairs changed 0\n",
      "fullSet, iter: 3 i:225, pairs changed 0\n",
      "fullSet, iter: 3 i:226, pairs changed 0\n",
      "fullSet, iter: 3 i:227, pairs changed 0\n",
      "fullSet, iter: 3 i:228, pairs changed 0\n",
      "fullSet, iter: 3 i:229, pairs changed 0\n",
      "fullSet, iter: 3 i:230, pairs changed 0\n",
      "fullSet, iter: 3 i:231, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:232, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:233, pairs changed 0\n",
      "fullSet, iter: 3 i:234, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:235, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:236, pairs changed 0\n",
      "fullSet, iter: 3 i:237, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:238, pairs changed 0\n",
      "fullSet, iter: 3 i:239, pairs changed 0\n",
      "fullSet, iter: 3 i:240, pairs changed 0\n",
      "fullSet, iter: 3 i:241, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:242, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:243, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:244, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:245, pairs changed 0\n",
      "fullSet, iter: 3 i:246, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:247, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:248, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:249, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:250, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:251, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:252, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:253, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:254, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:255, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:256, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:257, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:258, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:259, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:260, pairs changed 0\n",
      "fullSet, iter: 3 i:261, pairs changed 0\n",
      "fullSet, iter: 3 i:262, pairs changed 0\n",
      "fullSet, iter: 3 i:263, pairs changed 0\n",
      "fullSet, iter: 3 i:264, pairs changed 0\n",
      "fullSet, iter: 3 i:265, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:266, pairs changed 0\n",
      "fullSet, iter: 3 i:267, pairs changed 0\n",
      "fullSet, iter: 3 i:268, pairs changed 0\n",
      "fullSet, iter: 3 i:269, pairs changed 0\n",
      "fullSet, iter: 3 i:270, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:271, pairs changed 0\n",
      "fullSet, iter: 3 i:272, pairs changed 0\n",
      "fullSet, iter: 3 i:273, pairs changed 0\n",
      "fullSet, iter: 3 i:274, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:275, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:276, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:277, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:278, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:279, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:280, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:281, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:282, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:283, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:284, pairs changed 0\n",
      "fullSet, iter: 3 i:285, pairs changed 0\n",
      "fullSet, iter: 3 i:286, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:287, pairs changed 0\n",
      "fullSet, iter: 3 i:288, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:289, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:290, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:291, pairs changed 0\n",
      "fullSet, iter: 3 i:292, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:293, pairs changed 0\n",
      "fullSet, iter: 3 i:294, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:295, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:296, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:297, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:298, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:299, pairs changed 0\n",
      "fullSet, iter: 3 i:300, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:301, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:302, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:303, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:304, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:305, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:306, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:307, pairs changed 0\n",
      "fullSet, iter: 3 i:308, pairs changed 0\n",
      "fullSet, iter: 3 i:309, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:310, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:311, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:312, pairs changed 0\n",
      "fullSet, iter: 3 i:313, pairs changed 0\n",
      "fullSet, iter: 3 i:314, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:315, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:316, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:317, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:318, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:319, pairs changed 0\n",
      "fullSet, iter: 3 i:320, pairs changed 0\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "j not moving enough\n",
      "fullSet, iter: 3 i:321, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:322, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:323, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:324, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:325, pairs changed 0\n",
      "fullSet, iter: 3 i:326, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:327, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:328, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:329, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:330, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:331, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:332, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:333, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:334, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:335, pairs changed 0\n",
      "fullSet, iter: 3 i:336, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:337, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:338, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:339, pairs changed 0\n",
      "fullSet, iter: 3 i:340, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:341, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:342, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:343, pairs changed 0\n",
      "fullSet, iter: 3 i:344, pairs changed 0\n",
      "fullSet, iter: 3 i:345, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:346, pairs changed 0\n",
      "fullSet, iter: 3 i:347, pairs changed 0\n",
      "fullSet, iter: 3 i:348, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:349, pairs changed 0\n",
      "fullSet, iter: 3 i:350, pairs changed 0\n",
      "fullSet, iter: 3 i:351, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:352, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:353, pairs changed 0\n",
      "fullSet, iter: 3 i:354, pairs changed 0\n",
      "fullSet, iter: 3 i:355, pairs changed 0\n",
      "fullSet, iter: 3 i:356, pairs changed 0\n",
      "fullSet, iter: 3 i:357, pairs changed 0\n",
      "fullSet, iter: 3 i:358, pairs changed 0\n",
      "fullSet, iter: 3 i:359, pairs changed 0\n",
      "fullSet, iter: 3 i:360, pairs changed 0\n",
      "fullSet, iter: 3 i:361, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:362, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:363, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:364, pairs changed 0\n",
      "fullSet, iter: 3 i:365, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:366, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:367, pairs changed 0\n",
      "fullSet, iter: 3 i:368, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:369, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:370, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:371, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:372, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:373, pairs changed 0\n",
      "fullSet, iter: 3 i:374, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:375, pairs changed 0\n",
      "fullSet, iter: 3 i:376, pairs changed 0\n",
      "fullSet, iter: 3 i:377, pairs changed 0\n",
      "fullSet, iter: 3 i:378, pairs changed 0\n",
      "fullSet, iter: 3 i:379, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:380, pairs changed 0\n",
      "fullSet, iter: 3 i:381, pairs changed 0\n",
      "fullSet, iter: 3 i:382, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:383, pairs changed 0\n",
      "fullSet, iter: 3 i:384, pairs changed 0\n",
      "fullSet, iter: 3 i:385, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:386, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:387, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:388, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:389, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:390, pairs changed 0\n",
      "fullSet, iter: 3 i:391, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:392, pairs changed 0\n",
      "fullSet, iter: 3 i:393, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:394, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:395, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:396, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:397, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:398, pairs changed 0\n",
      "L==H\n",
      "fullSet, iter: 3 i:399, pairs changed 0\n",
      "fullSet, iter: 3 i:400, pairs changed 0\n",
      "j not moving enough\n",
      "fullSet, iter: 3 i:401, pairs changed 0\n",
      "iteration number: 4\n",
      "there are 49 Support Vectors\n",
      "the training error rate is: 0.000000\n",
      "the test error rate is: 0.016129\n"
     ]
    }
   ],
   "source": [
    "testDigits(('rbf', 20))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
